home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000114.unknown < prev    next >
Text File  |  2013-04-03  |  96KB  |  3,484 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. WebInspector.ApplicationCacheItemsView = function(model, frameId)
  8. {
  9. WebInspector.View.call(this);
  10.  
  11. this._model = model;
  12.  
  13. this.element.addStyleClass("storage-view");
  14. this.element.addStyleClass("table");
  15.  
  16.  
  17. this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
  18. this.deleteButton.visible = false;
  19. this.deleteButton.addEventListener("click", this._deleteButtonClicked, this);
  20.  
  21. this.connectivityIcon = document.createElement("img");
  22. this.connectivityIcon.className = "storage-application-cache-connectivity-icon";
  23. this.connectivityIcon.src = "";
  24. this.connectivityMessage = document.createElement("span");
  25. this.connectivityMessage.className = "storage-application-cache-connectivity";
  26. this.connectivityMessage.textContent = "";
  27.  
  28. this.divider = document.createElement("span");
  29. this.divider.className = "status-bar-item status-bar-divider";
  30.  
  31. this.statusIcon = document.createElement("img");
  32. this.statusIcon.className = "storage-application-cache-status-icon";
  33. this.statusIcon.src = "";
  34. this.statusMessage = document.createElement("span");
  35. this.statusMessage.className = "storage-application-cache-status";
  36. this.statusMessage.textContent = "";
  37.  
  38. this._frameId = frameId;
  39.  
  40. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("No Application Cache information available."));
  41. this._emptyView.show(this.element);
  42.  
  43. this._markDirty();
  44.  
  45. var status = this._model.frameManifestStatus(frameId);
  46. this.updateStatus(status);
  47.  
  48. this.updateNetworkState(this._model.onLine);
  49.  
  50.  
  51.  
  52. this.deleteButton.element.style.display = "none";
  53. }
  54.  
  55. WebInspector.ApplicationCacheItemsView.prototype = {
  56. get statusBarItems()
  57. {
  58. return [
  59. this.deleteButton.element,
  60. this.connectivityIcon, this.connectivityMessage, this.divider,
  61. this.statusIcon, this.statusMessage
  62. ];
  63. },
  64.  
  65. wasShown: function()
  66. {
  67. this._maybeUpdate();
  68. },
  69.  
  70. willHide: function()
  71. {
  72. this.deleteButton.visible = false;
  73. },
  74.  
  75. _maybeUpdate: function()
  76. {
  77. if (!this.isShowing() || !this._viewDirty)
  78. return;
  79.  
  80. this._update();
  81. this._viewDirty = false;
  82. },
  83.  
  84. _markDirty: function()
  85. {
  86. this._viewDirty = true;
  87. },
  88.  
  89.  
  90. updateStatus: function(status)
  91. {
  92. var oldStatus = this._status;
  93. this._status = status;
  94.  
  95. var statusInformation = {};
  96.  
  97. statusInformation[applicationCache.UNCACHED]    = { src: "Images/errorRedDot.png", text: "UNCACHED" };
  98. statusInformation[applicationCache.IDLE]        = { src: "Images/successGreenDot.png", text: "IDLE" };
  99. statusInformation[applicationCache.CHECKING]    = { src: "Images/warningOrangeDot.png",  text: "CHECKING" };
  100. statusInformation[applicationCache.DOWNLOADING] = { src: "Images/warningOrangeDot.png",  text: "DOWNLOADING" };
  101. statusInformation[applicationCache.UPDATEREADY] = { src: "Images/successGreenDot.png",  text: "UPDATEREADY" };
  102. statusInformation[applicationCache.OBSOLETE]    = { src: "Images/errorRedDot.png",      text: "OBSOLETE" };
  103.  
  104. var info = statusInformation[status] || statusInformation[applicationCache.UNCACHED];
  105.  
  106. this.statusIcon.src = info.src;
  107. this.statusMessage.textContent = info.text;
  108.  
  109. if (this.isShowing() && this._status === applicationCache.IDLE && (oldStatus === applicationCache.UPDATEREADY || !this._resources))
  110. this._markDirty();
  111. this._maybeUpdate();
  112. },
  113.  
  114.  
  115. updateNetworkState: function(isNowOnline)
  116. {
  117. if (isNowOnline) {
  118. this.connectivityIcon.src = "Images/successGreenDot.png";
  119. this.connectivityMessage.textContent = WebInspector.UIString("Online");
  120. } else {
  121. this.connectivityIcon.src = "Images/errorRedDot.png";
  122. this.connectivityMessage.textContent = WebInspector.UIString("Offline");
  123. }
  124. },
  125.  
  126. _update: function()
  127. {
  128. this._model.requestApplicationCache(this._frameId, this._updateCallback.bind(this));
  129. },
  130.  
  131.  
  132. _updateCallback: function(applicationCache)
  133. {
  134. if (!applicationCache || !applicationCache.manifestURL) {
  135. delete this._manifest;
  136. delete this._creationTime;
  137. delete this._updateTime;
  138. delete this._size;
  139. delete this._resources;
  140.  
  141. this._emptyView.show(this.element);
  142. this.deleteButton.visible = false;
  143. if (this._dataGrid)
  144. this._dataGrid.element.addStyleClass("hidden");
  145. return;
  146. }
  147.  
  148. this._manifest = applicationCache.manifestURL;
  149. this._creationTime = applicationCache.creationTime;
  150. this._updateTime = applicationCache.updateTime;
  151. this._size = applicationCache.size;
  152. this._resources = applicationCache.resources;
  153.  
  154. if (!this._dataGrid)
  155. this._createDataGrid();
  156.  
  157. this._populateDataGrid();
  158. this._dataGrid.autoSizeColumns(20, 80);
  159. this._dataGrid.element.removeStyleClass("hidden");
  160. this._emptyView.detach();
  161. this.deleteButton.visible = true;
  162.  
  163.  
  164.  
  165.  
  166. },
  167.  
  168. _createDataGrid: function()
  169. {
  170. var columns = { 0: {}, 1: {}, 2: {} };
  171. columns[0].title = WebInspector.UIString("Resource");
  172. columns[0].sort = "ascending";
  173. columns[0].sortable = true;
  174. columns[1].title = WebInspector.UIString("Type");
  175. columns[1].sortable = true;
  176. columns[2].title = WebInspector.UIString("Size");
  177. columns[2].aligned = "right";
  178. columns[2].sortable = true;
  179. this._dataGrid = new WebInspector.DataGrid(columns);
  180. this._dataGrid.show(this.element);
  181. this._dataGrid.addEventListener("sorting changed", this._populateDataGrid, this);
  182. },
  183.  
  184. _populateDataGrid: function()
  185. {
  186. var selectedResource = this._dataGrid.selectedNode ? this._dataGrid.selectedNode.resource : null;
  187. var sortDirection = this._dataGrid.sortOrder === "ascending" ? 1 : -1;
  188.  
  189. function numberCompare(field, resource1, resource2)
  190. {
  191. return sortDirection * (resource1[field] - resource2[field]);
  192. }
  193. function localeCompare(field, resource1, resource2)
  194. {
  195. return sortDirection * (resource1[field] + "").localeCompare(resource2[field] + "")
  196. }
  197.  
  198. var comparator;
  199. switch (parseInt(this._dataGrid.sortColumnIdentifier, 10)) {
  200. case 0: comparator = localeCompare.bind(this, "name"); break;
  201. case 1: comparator = localeCompare.bind(this, "type"); break;
  202. case 2: comparator = numberCompare.bind(this, "size"); break;
  203. default: localeCompare.bind(this, "resource"); 
  204. }
  205.  
  206. this._resources.sort(comparator);
  207. this._dataGrid.rootNode().removeChildren();
  208.  
  209. var nodeToSelect;
  210. for (var i = 0; i < this._resources.length; ++i) {
  211. var data = {};
  212. var resource = this._resources[i];
  213. data[0] = resource.url;
  214. data[1] = resource.type;
  215. data[2] = Number.bytesToString(resource.size);
  216. var node = new WebInspector.DataGridNode(data);
  217. node.resource = resource;
  218. node.selectable = true;
  219. this._dataGrid.rootNode().appendChild(node);
  220. if (resource === selectedResource) {
  221. nodeToSelect = node;
  222. nodeToSelect.selected = true;
  223. }
  224. }
  225.  
  226. if (!nodeToSelect && this._dataGrid.rootNode().children.length)
  227. this._dataGrid.rootNode().children[0].selected = true;
  228. },
  229.  
  230. _deleteButtonClicked: function(event)
  231. {
  232. if (!this._dataGrid || !this._dataGrid.selectedNode)
  233. return;
  234.  
  235.  
  236. this._deleteCallback(this._dataGrid.selectedNode);
  237. },
  238.  
  239. _deleteCallback: function(node)
  240. {
  241.  
  242.  
  243.  
  244. },
  245.  
  246. __proto__: WebInspector.View.prototype
  247. }
  248.  
  249. ;
  250.  
  251.  
  252.  
  253. WebInspector.DOMStorageItemsView = function(domStorage)
  254. {
  255. WebInspector.View.call(this);
  256.  
  257. this.domStorage = domStorage;
  258.  
  259. this.element.addStyleClass("storage-view");
  260. this.element.addStyleClass("table");
  261.  
  262. this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
  263. this.deleteButton.visible = false;
  264. this.deleteButton.addEventListener("click", this._deleteButtonClicked, this);
  265.  
  266. this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
  267. this.refreshButton.addEventListener("click", this._refreshButtonClicked, this);
  268. }
  269.  
  270. WebInspector.DOMStorageItemsView.prototype = {
  271. get statusBarItems()
  272. {
  273. return [this.refreshButton.element, this.deleteButton.element];
  274. },
  275.  
  276. wasShown: function()
  277. {
  278. this.update();
  279. },
  280.  
  281. willHide: function()
  282. {
  283. this.deleteButton.visible = false;
  284. },
  285.  
  286. update: function()
  287. {
  288. this.detachChildViews();
  289. this.domStorage.getEntries(this._showDOMStorageEntries.bind(this));
  290. },
  291.  
  292. _showDOMStorageEntries: function(error, entries)
  293. {
  294. if (error)
  295. return;
  296.  
  297. this._dataGrid = this._dataGridForDOMStorageEntries(entries);
  298. this._dataGrid.show(this.element);
  299. this._dataGrid.autoSizeColumns(10);
  300. this.deleteButton.visible = true;
  301. },
  302.  
  303. _dataGridForDOMStorageEntries: function(entries)
  304. {
  305. var columns = {};
  306. columns[0] = {};
  307. columns[1] = {};
  308. columns[0].title = WebInspector.UIString("Key");
  309. columns[1].title = WebInspector.UIString("Value");
  310.  
  311. var nodes = [];
  312.  
  313. var keys = [];
  314. var length = entries.length;
  315. for (var i = 0; i < entries.length; i++) {
  316. var data = {};
  317.  
  318. var key = entries[i][0];
  319. data[0] = key;
  320. var value = entries[i][1];
  321. data[1] = value;
  322. var node = new WebInspector.DataGridNode(data, false);
  323. node.selectable = true;
  324. nodes.push(node);
  325. keys.push(key);
  326. }
  327.  
  328. var dataGrid = new WebInspector.DataGrid(columns, this._editingCallback.bind(this), this._deleteCallback.bind(this));
  329. length = nodes.length;
  330. for (var i = 0; i < length; ++i)
  331. dataGrid.rootNode().appendChild(nodes[i]);
  332. dataGrid.addCreationNode(false);
  333. if (length > 0)
  334. nodes[0].selected = true;
  335. return dataGrid;
  336. },
  337.  
  338. _deleteButtonClicked: function(event)
  339. {
  340. if (!this._dataGrid || !this._dataGrid.selectedNode)
  341. return;
  342.  
  343. this._deleteCallback(this._dataGrid.selectedNode);
  344. },
  345.  
  346. _refreshButtonClicked: function(event)
  347. {
  348. this.update();
  349. },
  350.  
  351. _editingCallback: function(editingNode, columnIdentifier, oldText, newText)
  352. {
  353. var domStorage = this.domStorage;
  354. if (columnIdentifier === 0) {
  355. if (oldText)
  356. domStorage.removeItem(oldText);
  357.  
  358. domStorage.setItem(newText, editingNode.data[1]);
  359. } else {
  360. domStorage.setItem(editingNode.data[0], newText);
  361. }
  362.  
  363. this.update();
  364. },
  365.  
  366. _deleteCallback: function(node)
  367. {
  368. if (!node || node.isCreationNode)
  369. return;
  370.  
  371. if (this.domStorage)
  372. this.domStorage.removeItem(node.data[0]);
  373.  
  374. this.update();
  375. },
  376.  
  377. __proto__: WebInspector.View.prototype
  378. }
  379. ;
  380.  
  381.  
  382.  
  383. WebInspector.DatabaseQueryView = function(database)
  384. {
  385. WebInspector.View.call(this);
  386.  
  387. this.database = database;
  388.  
  389. this.element.addStyleClass("storage-view");
  390. this.element.addStyleClass("query");
  391. this.element.addStyleClass("monospace");
  392. this.element.addEventListener("selectstart", this._selectStart.bind(this), false);
  393.  
  394. this._promptElement = document.createElement("div");
  395. this._promptElement.className = "database-query-prompt";
  396. this._promptElement.appendChild(document.createElement("br"));
  397. this._promptElement.addEventListener("keydown", this._promptKeyDown.bind(this), true);
  398. this.element.appendChild(this._promptElement);
  399.  
  400. this.prompt = new WebInspector.TextPromptWithHistory(this.completions.bind(this), " ");
  401. this.prompt.attach(this._promptElement);
  402.  
  403. this.element.addEventListener("click", this._messagesClicked.bind(this), true);
  404. }
  405.  
  406. WebInspector.DatabaseQueryView.Events = {
  407. SchemaUpdated: "SchemaUpdated"
  408. }
  409.  
  410. WebInspector.DatabaseQueryView.prototype = {
  411. _messagesClicked: function()
  412. {
  413. if (!this.prompt.isCaretInsidePrompt() && window.getSelection().isCollapsed)
  414. this.prompt.moveCaretToEndOfPrompt();
  415. },
  416.  
  417.  
  418. completions: function(proxyElement, wordRange, force, completionsReadyCallback)
  419. {
  420. var prefix = wordRange.toString().toLowerCase();
  421. if (!prefix.length && !force)
  422. return;
  423.  
  424. var results = [];
  425.  
  426. function accumulateMatches(textArray)
  427. {
  428. for (var i = 0; i < textArray.length; ++i) {
  429. var text = textArray[i].toLowerCase();
  430. if (text.length < prefix.length)
  431. continue;
  432. if (!text.startsWith(prefix))
  433. continue;
  434. results.push(textArray[i]);
  435. }
  436. }
  437.  
  438. function tableNamesCallback(tableNames)
  439. {
  440. accumulateMatches(tableNames.map(function(name) { return name + " " }));
  441. accumulateMatches(["SELECT ", "FROM ", "WHERE ", "LIMIT ", "DELETE FROM ", "CREATE ", "DROP ", "TABLE ", "INDEX ", "UPDATE ", "INSERT INTO ", "VALUES ("]);
  442.  
  443. completionsReadyCallback(results);
  444. }
  445. this.database.getTableNames(tableNamesCallback);
  446. },
  447.  
  448. _selectStart: function(event)
  449. {
  450. if (this._selectionTimeout)
  451. clearTimeout(this._selectionTimeout);
  452.  
  453. this.prompt.clearAutoComplete();
  454.  
  455. function moveBackIfOutside()
  456. {
  457. delete this._selectionTimeout;
  458. if (!this.prompt.isCaretInsidePrompt() && window.getSelection().isCollapsed)
  459. this.prompt.moveCaretToEndOfPrompt();
  460. this.prompt.autoCompleteSoon();
  461. }
  462.  
  463. this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100);
  464. },
  465.  
  466. _promptKeyDown: function(event)
  467. {
  468. if (isEnterKey(event)) {
  469. this._enterKeyPressed(event);
  470. return;
  471. }
  472. },
  473.  
  474. _enterKeyPressed: function(event)
  475. {
  476. event.consume(true);
  477.  
  478. this.prompt.clearAutoComplete(true);
  479.  
  480. var query = this.prompt.text;
  481. if (!query.length)
  482. return;
  483.  
  484. this.prompt.pushHistoryItem(query);
  485. this.prompt.text = "";
  486.  
  487. this.database.executeSql(query, this._queryFinished.bind(this, query), this._queryError.bind(this, query));
  488. },
  489.  
  490. _queryFinished: function(query, columnNames, values)
  491. {
  492. var dataGrid = WebInspector.DataGrid.createSortableDataGrid(columnNames, values);
  493. var trimmedQuery = query.trim();
  494.  
  495. if (dataGrid) {
  496. dataGrid.element.addStyleClass("inline");
  497. this._appendViewQueryResult(trimmedQuery, dataGrid);
  498. dataGrid.autoSizeColumns(5);
  499. }
  500.  
  501. if (trimmedQuery.match(/^create /i) || trimmedQuery.match(/^drop table /i))
  502. this.dispatchEventToListeners(WebInspector.DatabaseQueryView.Events.SchemaUpdated, this.database);
  503. },
  504.  
  505. _queryError: function(query, errorMessage)
  506. {
  507. this._appendErrorQueryResult(query, errorMessage);
  508. },
  509.  
  510.  
  511. _appendViewQueryResult: function(query, view)
  512. {
  513. var resultElement = this._appendQueryResult(query);
  514. view.show(resultElement);
  515.  
  516. this._promptElement.scrollIntoView(false);
  517. },
  518.  
  519.  
  520. _appendErrorQueryResult: function(query, errorText)
  521. {
  522. var resultElement = this._appendQueryResult(query);
  523. resultElement.addStyleClass("error")
  524. resultElement.textContent = errorText;
  525.  
  526. this._promptElement.scrollIntoView(false);
  527. },
  528.  
  529. _appendQueryResult: function(query)
  530. {
  531. var element = document.createElement("div");
  532. element.className = "database-user-query";
  533. this.element.insertBefore(element, this.prompt.proxyElement);
  534.  
  535. var commandTextElement = document.createElement("span");
  536. commandTextElement.className = "database-query-text";
  537. commandTextElement.textContent = query;
  538. element.appendChild(commandTextElement);
  539.  
  540. var resultElement = document.createElement("div");
  541. resultElement.className = "database-query-result";
  542. element.appendChild(resultElement);
  543. return resultElement;
  544. },
  545.  
  546. __proto__: WebInspector.View.prototype
  547. }
  548. ;
  549.  
  550.  
  551.  
  552. WebInspector.DatabaseTableView = function(database, tableName)
  553. {
  554. WebInspector.View.call(this);
  555.  
  556. this.database = database;
  557. this.tableName = tableName;
  558.  
  559. this.element.addStyleClass("storage-view");
  560. this.element.addStyleClass("table");
  561.  
  562. this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
  563. this.refreshButton.addEventListener("click", this._refreshButtonClicked, this);
  564. }
  565.  
  566. WebInspector.DatabaseTableView.prototype = {
  567. wasShown: function()
  568. {
  569. this.update();
  570. },
  571.  
  572. get statusBarItems()
  573. {
  574. return [this.refreshButton.element];
  575. },
  576.  
  577.  
  578. _escapeTableName: function(tableName)
  579. {
  580. return tableName.replace(/\"/g, "\"\"");
  581. },
  582.  
  583. update: function()
  584. {
  585. this.database.executeSql("SELECT * FROM \"" + this._escapeTableName(this.tableName) + "\"", this._queryFinished.bind(this), this._queryError.bind(this));
  586. },
  587.  
  588. _queryFinished: function(columnNames, values)
  589. {
  590. this.detachChildViews();
  591. this.element.removeChildren();
  592.  
  593. var dataGrid = WebInspector.DataGrid.createSortableDataGrid(columnNames, values);
  594. if (!dataGrid) {
  595. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("The ΓÇ£%sΓÇ¥\ntable is empty.", this.tableName));
  596. this._emptyView.show(this.element);
  597. return;
  598. }
  599. dataGrid.show(this.element);
  600. dataGrid.autoSizeColumns(5);
  601. },
  602.  
  603. _queryError: function(error)
  604. {
  605. this.detachChildViews();
  606. this.element.removeChildren();
  607.  
  608. var errorMsgElement = document.createElement("div");
  609. errorMsgElement.className = "storage-table-error";
  610. errorMsgElement.textContent = WebInspector.UIString("An error occurred trying to\nread the ΓÇ£%sΓÇ¥ table.", this.tableName);
  611. this.element.appendChild(errorMsgElement);
  612. },
  613.  
  614. _refreshButtonClicked: function(event)
  615. {
  616. this.update();
  617. },
  618.  
  619. __proto__: WebInspector.View.prototype
  620. }
  621. ;
  622.  
  623.  
  624.  
  625. WebInspector.DirectoryContentView = function()
  626. {
  627. const indexes = WebInspector.DirectoryContentView.columnIndexes;
  628. var columns = {};
  629. columns[indexes.Name] = {};
  630. columns[indexes.Name].title = WebInspector.UIString("Name");
  631. columns[indexes.Name].sort = "ascending";
  632. columns[indexes.Name].sortable = true;
  633. columns[indexes.Name].width = "20%";
  634. columns[indexes.URL] = {};
  635. columns[indexes.URL].title = WebInspector.UIString("URL");
  636. columns[indexes.URL].sortable = true;
  637. columns[indexes.URL].width = "20%";
  638. columns[indexes.Type] = {};
  639. columns[indexes.Type].title = WebInspector.UIString("Type");
  640. columns[indexes.Type].sortable = true;
  641. columns[indexes.Type].width = "15%";
  642. columns[indexes.Size] = {};
  643. columns[indexes.Size].title = WebInspector.UIString("Size");
  644. columns[indexes.Size].sortable = true;
  645. columns[indexes.Size].width = "10%";
  646. columns[indexes.ModificationTime] = {};
  647. columns[indexes.ModificationTime].title = WebInspector.UIString("Modification Time");
  648. columns[indexes.ModificationTime].sortable = true;
  649. columns[indexes.ModificationTime].width = "25%";
  650.  
  651. WebInspector.DataGrid.call(this, columns);
  652. this.addEventListener("sorting changed", this._sort, this);
  653. }
  654.  
  655. WebInspector.DirectoryContentView.columnIndexes = {
  656. Name: "0",
  657. URL: "1",
  658. Type: "2",
  659. Size: "3",
  660. ModificationTime: "4"
  661. }
  662.  
  663. WebInspector.DirectoryContentView.prototype = {
  664.  
  665. showEntries: function(entries)
  666. {
  667. const indexes = WebInspector.DirectoryContentView.columnIndexes;
  668. this.rootNode().removeChildren();
  669. for (var i = 0; i < entries.length; ++i)
  670. this.rootNode().appendChild(new WebInspector.DirectoryContentView.Node(entries[i]));
  671. },
  672.  
  673. _sort: function()
  674. {
  675. var column =   (this.sortColumnIdentifier);
  676. this.sortNodes(WebInspector.DirectoryContentView.Node.comparator(column, this.sortOrder === "descending"), false);
  677. },
  678.  
  679. __proto__: WebInspector.DataGrid.prototype
  680. }
  681.  
  682.  
  683. WebInspector.DirectoryContentView.Node = function(entry)
  684. {
  685. const indexes = WebInspector.DirectoryContentView.columnIndexes;
  686. var data = {};
  687. data[indexes.Name] = entry.name;
  688. data[indexes.URL] = entry.url;
  689. data[indexes.Type] = entry.isDirectory ? WebInspector.UIString("Directory") : entry.mimeType;
  690. data[indexes.Size] = "";
  691. data[indexes.ModificationTime] = "";
  692.  
  693. WebInspector.DataGridNode.call(this, data);
  694. this._entry = entry;
  695. this._metadata = null;
  696.  
  697. this._entry.requestMetadata(this._metadataReceived.bind(this));
  698. }
  699.  
  700.  
  701. WebInspector.DirectoryContentView.Node.comparator = function(column, reverse)
  702. {
  703. var reverseFactor = reverse ? -1 : 1;
  704. const indexes = WebInspector.DirectoryContentView.columnIndexes;
  705.  
  706. switch (column) {
  707. case indexes.Name:
  708. case indexes.URL:
  709. return function(x, y)
  710. {
  711. return isDirectoryCompare(x, y) || nameCompare(x, y);
  712. };
  713. case indexes.Type:
  714. return function(x, y)
  715. {
  716. return isDirectoryCompare(x ,y) || typeCompare(x, y) || nameCompare(x, y);
  717. };
  718. case indexes.Size:
  719. return function(x, y)
  720. {
  721. return isDirectoryCompare(x, y) || sizeCompare(x, y) || nameCompare(x, y);
  722. };
  723. case indexes.ModificationTime:
  724. return function(x, y)
  725. {
  726. return isDirectoryCompare(x, y) || modificationTimeCompare(x, y) || nameCompare(x, y);
  727. };
  728. }
  729.  
  730. function isDirectoryCompare(x, y)
  731. {
  732. if (x._entry.isDirectory != y._entry.isDirectory)
  733. return y._entry.isDirectory ? 1 : -1;
  734. return 0;
  735. }
  736.  
  737. function nameCompare(x, y)
  738. {
  739. return reverseFactor * x._entry.name.localeCompare(y._entry.name);
  740. }
  741.  
  742. function typeCompare(x, y)
  743. {
  744. return reverseFactor * (x._entry.mimeType || "").localeCompare(y._entry.mimeType || "");
  745. }
  746.  
  747. function sizeCompare(x, y)
  748. {
  749. return reverseFactor * ((x._metadata ? x._metadata.size : 0) - (y._metadata ? y._metadata.size : 0));
  750. }
  751.  
  752. function modificationTimeCompare(x, y)
  753. {
  754. return reverseFactor * ((x._metadata ? x._metadata.modificationTime : 0) - (y._metadata ? y._metadata.modificationTime : 0));
  755. }
  756. }
  757.  
  758. WebInspector.DirectoryContentView.Node.prototype = {
  759.  
  760. _metadataReceived: function(errorCode, metadata)
  761. {
  762. const indexes = WebInspector.DirectoryContentView.columnIndexes;
  763. if (errorCode !== 0)
  764. return;
  765.  
  766. this._metadata = metadata;
  767. var data = this.data;
  768. if (this._entry.isDirectory)
  769. data[indexes.Size] = WebInspector.UIString("-");
  770. else
  771. data[indexes.Size] = Number.bytesToString(metadata.size);
  772. data[indexes.ModificationTime] = new Date(metadata.modificationTime).toGMTString();
  773. this.data = data;
  774. },
  775.  
  776. __proto__: WebInspector.DataGridNode.prototype
  777. }
  778. ;
  779.  
  780.  
  781.  
  782. WebInspector.IDBDatabaseView = function(database)
  783. {
  784. WebInspector.View.call(this);
  785. this.registerRequiredCSS("indexedDBViews.css");
  786.  
  787. this.element.addStyleClass("fill");
  788. this.element.addStyleClass("indexed-db-database-view");
  789.  
  790. this._headersListElement = this.element.createChild("ol", "outline-disclosure");
  791. this._headersTreeOutline = new TreeOutline(this._headersListElement);
  792. this._headersTreeOutline.expandTreeElementsWhenArrowing = true;
  793.  
  794. this._securityOriginTreeElement = new TreeElement("", null, false);
  795. this._securityOriginTreeElement.selectable = false;
  796. this._headersTreeOutline.appendChild(this._securityOriginTreeElement);
  797.  
  798. this._nameTreeElement = new TreeElement("", null, false);
  799. this._nameTreeElement.selectable = false;
  800. this._headersTreeOutline.appendChild(this._nameTreeElement);
  801.  
  802. this._intVersionTreeElement = new TreeElement("", null, false);
  803. this._intVersionTreeElement.selectable = false;
  804. this._headersTreeOutline.appendChild(this._intVersionTreeElement);
  805.  
  806. this._stringVersionTreeElement = new TreeElement("", null, false);
  807. this._stringVersionTreeElement.selectable = false;
  808. this._headersTreeOutline.appendChild(this._stringVersionTreeElement);
  809.  
  810. this.update(database);
  811. }
  812.  
  813. WebInspector.IDBDatabaseView.prototype = {
  814.  
  815. _formatHeader: function(name, value)
  816. {
  817. var fragment = document.createDocumentFragment();
  818. fragment.createChild("div", "attribute-name").textContent = name + ":";
  819. fragment.createChild("div", "attribute-value source-code").textContent = value;
  820.  
  821. return fragment;
  822. },
  823.  
  824. _refreshDatabase: function()
  825. {
  826. this._securityOriginTreeElement.title = this._formatHeader(WebInspector.UIString("Security origin"), this._database.databaseId.securityOrigin);
  827. this._nameTreeElement.title = this._formatHeader(WebInspector.UIString("Name"), this._database.databaseId.name);
  828. this._stringVersionTreeElement.title = this._formatHeader(WebInspector.UIString("String Version"), this._database.version);
  829. this._intVersionTreeElement.title = this._formatHeader(WebInspector.UIString("Integer Version"), this._database.intVersion);
  830. },
  831.  
  832.  
  833. update: function(database)
  834. {
  835. this._database = database;
  836. this._refreshDatabase();
  837. },
  838.  
  839. __proto__: WebInspector.View.prototype
  840. }
  841.  
  842.  
  843.  
  844. WebInspector.IDBDataView = function(model, databaseId, objectStore, index)
  845. {
  846. WebInspector.View.call(this);
  847. this.registerRequiredCSS("indexedDBViews.css");
  848.  
  849. this._model = model;
  850. this._databaseId = databaseId;
  851. this._isIndex = !!index;
  852.  
  853. this.element.addStyleClass("indexed-db-data-view");
  854.  
  855. var editorToolbar = this._createEditorToolbar();
  856. this.element.appendChild(editorToolbar);
  857.  
  858. this._dataGridContainer = this.element.createChild("div", "fill");
  859. this._dataGridContainer.addStyleClass("data-grid-container");
  860.  
  861. this._refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
  862. this._refreshButton.addEventListener("click", this._refreshButtonClicked, this);
  863.  
  864. this._pageSize = 50;
  865. this._skipCount = 0;
  866.  
  867. this.update(objectStore, index);
  868. this._entries = [];
  869. }
  870.  
  871. WebInspector.IDBDataView.prototype = {
  872.  
  873. _createDataGrid: function()
  874. {
  875. var columns = {};
  876. columns["number"] = {};
  877. columns["number"].title = WebInspector.UIString("#");
  878. columns["number"].width = "50px";
  879.  
  880. var keyPath = this._isIndex ? this._index.keyPath : this._objectStore.keyPath;
  881. columns["key"] = {};
  882. columns["key"].titleDOMFragment = this._keyColumnHeaderFragment(WebInspector.UIString("Key"), keyPath);
  883.  
  884. if (this._isIndex) {
  885. columns["primaryKey"] = {};
  886. columns["primaryKey"].titleDOMFragment = this._keyColumnHeaderFragment(WebInspector.UIString("Primary key"), this._objectStore.keyPath);
  887. }
  888.  
  889. columns["value"] = {};
  890. columns["value"].title = WebInspector.UIString("Value");
  891.  
  892. var dataGrid = new WebInspector.DataGrid(columns);
  893. return dataGrid;
  894. },
  895.  
  896.  
  897. _keyColumnHeaderFragment: function(prefix, keyPath)
  898. {
  899. var keyColumnHeaderFragment = document.createDocumentFragment();
  900. keyColumnHeaderFragment.appendChild(document.createTextNode(prefix));
  901. if (keyPath === null)
  902. return keyColumnHeaderFragment;
  903.  
  904. keyColumnHeaderFragment.appendChild(document.createTextNode(" (" + WebInspector.UIString("Key path: ")));
  905. if (keyPath instanceof Array) {
  906. keyColumnHeaderFragment.appendChild(document.createTextNode("["));
  907. for (var i = 0; i < keyPath.length; ++i) {
  908. if (i != 0)
  909. keyColumnHeaderFragment.appendChild(document.createTextNode(", "));
  910. keyColumnHeaderFragment.appendChild(this._keyPathStringFragment(keyPath[i]));
  911. }
  912. keyColumnHeaderFragment.appendChild(document.createTextNode("]"));
  913. } else {
  914. var keyPathString =   (keyPath);
  915. keyColumnHeaderFragment.appendChild(this._keyPathStringFragment(keyPathString));
  916. }
  917. keyColumnHeaderFragment.appendChild(document.createTextNode(")"));
  918. return keyColumnHeaderFragment;
  919. },
  920.  
  921.  
  922. _keyPathStringFragment: function(keyPathString)
  923. {
  924. var keyPathStringFragment = document.createDocumentFragment();
  925. keyPathStringFragment.appendChild(document.createTextNode("\""));
  926. var keyPathSpan = keyPathStringFragment.createChild("span", "source-code console-formatted-string");
  927. keyPathSpan.textContent = keyPathString;
  928. keyPathStringFragment.appendChild(document.createTextNode("\""));
  929. return keyPathStringFragment;
  930. },
  931.  
  932.  
  933. _createEditorToolbar: function()
  934. {
  935. var editorToolbar = document.createElement("div");
  936. editorToolbar.addStyleClass("status-bar");
  937. editorToolbar.addStyleClass("data-view-toolbar");
  938.  
  939. this._pageBackButton = editorToolbar.createChild("button", "back-button");
  940. this._pageBackButton.addStyleClass("status-bar-item");
  941. this._pageBackButton.title = WebInspector.UIString("Show previous page.");
  942. this._pageBackButton.disabled = true;
  943. this._pageBackButton.appendChild(document.createElement("img"));
  944. this._pageBackButton.addEventListener("click", this._pageBackButtonClicked.bind(this), false);
  945. editorToolbar.appendChild(this._pageBackButton);
  946.  
  947. this._pageForwardButton = editorToolbar.createChild("button", "forward-button");
  948. this._pageForwardButton.addStyleClass("status-bar-item");
  949. this._pageForwardButton.title = WebInspector.UIString("Show next page.");
  950. this._pageForwardButton.disabled = true;
  951. this._pageForwardButton.appendChild(document.createElement("img"));
  952. this._pageForwardButton.addEventListener("click", this._pageForwardButtonClicked.bind(this), false);
  953. editorToolbar.appendChild(this._pageForwardButton);
  954.  
  955. this._keyInputElement = editorToolbar.createChild("input", "key-input");
  956. this._keyInputElement.placeholder = WebInspector.UIString("Start from key");
  957. this._keyInputElement.addEventListener("paste", this._keyInputChanged.bind(this));
  958. this._keyInputElement.addEventListener("cut", this._keyInputChanged.bind(this));
  959. this._keyInputElement.addEventListener("keypress", this._keyInputChanged.bind(this));
  960. this._keyInputElement.addEventListener("keydown", this._keyInputChanged.bind(this));
  961.  
  962. return editorToolbar;
  963. },
  964.  
  965. _pageBackButtonClicked: function()
  966. {
  967. this._skipCount = Math.max(0, this._skipCount - this._pageSize);
  968. this._updateData(false);
  969. },
  970.  
  971. _pageForwardButtonClicked: function()
  972. {
  973. this._skipCount = this._skipCount + this._pageSize;
  974. this._updateData(false);
  975. },
  976.  
  977. _keyInputChanged: function()
  978. {
  979. window.setTimeout(this._updateData.bind(this, false), 0);
  980. },
  981.  
  982.  
  983. update: function(objectStore, index)
  984. {
  985. this._objectStore = objectStore;
  986. this._index = index;
  987.  
  988. if (this._dataGrid)
  989. this._dataGrid.detach();
  990. this._dataGrid = this._createDataGrid();
  991. this._dataGrid.show(this._dataGridContainer);
  992.  
  993. this._skipCount = 0;
  994. this._updateData(true);
  995. },
  996.  
  997.  
  998. _parseKey: function(keyString)
  999. {
  1000. var result;
  1001. try {
  1002. result = JSON.parse(keyString);
  1003. } catch (e) {
  1004. result = keyString;
  1005. }
  1006. return result;
  1007. },
  1008.  
  1009.  
  1010. _stringifyKey: function(key)
  1011. {
  1012. if (typeof(key) === "string")
  1013. return key;
  1014. return JSON.stringify(key);
  1015. },
  1016.  
  1017.  
  1018. _updateData: function(force)
  1019. {
  1020. var key = this._parseKey(this._keyInputElement.value);
  1021. var pageSize = this._pageSize;
  1022. var skipCount = this._skipCount;
  1023.  
  1024. if (!force && this._lastKey === key && this._lastPageSize === pageSize && this._lastSkipCount === skipCount)
  1025. return;
  1026.  
  1027. if (this._lastKey !== key || this._lastPageSize !== pageSize) {
  1028. skipCount = 0;
  1029. this._skipCount = 0;
  1030. }
  1031. this._lastKey = key;
  1032. this._lastPageSize = pageSize;
  1033. this._lastSkipCount = skipCount;
  1034.  
  1035.  
  1036. function callback(entries, hasMore)
  1037. {
  1038. this.clear();
  1039. this._entries = entries;
  1040. for (var i = 0; i < entries.length; ++i) {
  1041. var data = {};
  1042. data["number"] = i + skipCount;
  1043. data["key"] = entries[i].key;
  1044. data["primaryKey"] = entries[i].primaryKey;
  1045. data["value"] = entries[i].value;
  1046.  
  1047. var primaryKey = JSON.stringify(this._isIndex ? entries[i].primaryKey : entries[i].key);
  1048. var node = new WebInspector.IDBDataGridNode(data);
  1049. this._dataGrid.rootNode().appendChild(node);
  1050. }
  1051.  
  1052. this._pageBackButton.disabled = skipCount === 0;
  1053. this._pageForwardButton.disabled = !hasMore;
  1054. }
  1055.  
  1056. var idbKeyRange = key ? window.webkitIDBKeyRange.lowerBound(key) : null;
  1057. if (this._isIndex)
  1058. this._model.loadIndexData(this._databaseId, this._objectStore.name, this._index.name, idbKeyRange, skipCount, pageSize, callback.bind(this));
  1059. else
  1060. this._model.loadObjectStoreData(this._databaseId, this._objectStore.name, idbKeyRange, skipCount, pageSize, callback.bind(this));
  1061. },
  1062.  
  1063. _refreshButtonClicked: function(event)
  1064. {
  1065. this._updateData(true);
  1066. },
  1067.  
  1068. get statusBarItems()
  1069. {
  1070. return [this._refreshButton.element];
  1071. },
  1072.  
  1073. clear: function()
  1074. {
  1075. this._dataGrid.rootNode().removeChildren();
  1076. for (var i = 0; i < this._entries.length; ++i) {
  1077. this._entries[i].key.release();
  1078. this._entries[i].primaryKey.release();
  1079. this._entries[i].value.release();
  1080. }
  1081. this._entries = [];
  1082. },
  1083.  
  1084. __proto__: WebInspector.View.prototype
  1085. }
  1086.  
  1087.  
  1088. WebInspector.IDBDataGridNode = function(data)
  1089. {
  1090. WebInspector.DataGridNode.call(this, data, false);
  1091. this.selectable = false;
  1092. }
  1093.  
  1094. WebInspector.IDBDataGridNode.prototype = {
  1095.  
  1096. createCell: function(columnIdentifier)
  1097. {
  1098. var cell = WebInspector.DataGridNode.prototype.createCell.call(this, columnIdentifier);
  1099. var value = this.data[columnIdentifier];
  1100.  
  1101. switch (columnIdentifier) {
  1102. case "value":
  1103. case "key":
  1104. case "primaryKey":
  1105. cell.removeChildren();
  1106. this._formatValue(cell, value);
  1107. break;
  1108. default:
  1109. }
  1110.  
  1111. return cell;
  1112. },
  1113.  
  1114. _formatValue: function(cell, value)
  1115. {
  1116. var type = value.subtype || value.type;
  1117. var contents = cell.createChild("div", "source-code console-formatted-" + type);
  1118.  
  1119. switch (type) {
  1120. case "object":
  1121. case "array":
  1122. var section = new WebInspector.ObjectPropertiesSection(value, value.description)
  1123. section.editable = false;
  1124. section.skipProto = true;
  1125. contents.appendChild(section.element);
  1126. break;
  1127. case "string":
  1128. contents.addStyleClass("primitive-value");
  1129. contents.appendChild(document.createTextNode("\"" + value.description + "\""));
  1130. break;
  1131. default:
  1132. contents.addStyleClass("primitive-value");
  1133. contents.appendChild(document.createTextNode(value.description));
  1134. }
  1135. },
  1136.  
  1137. __proto__: WebInspector.DataGridNode.prototype
  1138. }
  1139.  
  1140. ;
  1141.  
  1142.  
  1143.  
  1144. WebInspector.FileContentView = function(file)
  1145. {
  1146. WebInspector.View.call(this);
  1147.  
  1148. this._innerView = null;
  1149. this._file = file;
  1150. this._content = null;
  1151. }
  1152.  
  1153. WebInspector.FileContentView.prototype = {
  1154. wasShown: function()
  1155. {
  1156. if (!this._innerView) {
  1157. if (this._file.isTextFile)
  1158. this._innerView = new WebInspector.EmptyView("");
  1159. else
  1160. this._innerView = new WebInspector.EmptyView(WebInspector.UIString("Binary File"));
  1161. this.refresh();
  1162. }
  1163.  
  1164. this._innerView.show(this.element);
  1165. },
  1166.  
  1167.  
  1168. _metadataReceived: function(errorCode, metadata)
  1169. {
  1170. if (errorCode || !metadata)
  1171. return;
  1172.  
  1173. if (this._content) {
  1174. if (!this._content.updateMetadata(metadata))
  1175. return;
  1176. var sourceFrame =   (this._innerView);
  1177. this._content.requestContent(sourceFrame.setContent.bind(sourceFrame));
  1178. } else {
  1179. this._innerView.detach();
  1180. this._content = new WebInspector.FileContentView.FileContentProvider(this._file, metadata);
  1181. this._innerView = new WebInspector.SourceFrame(this._content);
  1182. this._innerView.show(this.element);
  1183. }
  1184. },
  1185.  
  1186. refresh: function()
  1187. {
  1188. if (!this._innerView)
  1189. return;
  1190.  
  1191. if (this._file.isTextFile)
  1192. this._file.requestMetadata(this._metadataReceived.bind(this));
  1193. },
  1194.  
  1195. __proto__: WebInspector.View.prototype
  1196. }
  1197.  
  1198.  
  1199. WebInspector.FileContentView.FileContentProvider = function(file, metadata)
  1200. {
  1201. this._file = file;
  1202. this._metadata = metadata;
  1203. }
  1204.  
  1205. WebInspector.FileContentView.FileContentProvider.prototype = {
  1206.  
  1207. contentURL: function()
  1208. {
  1209. return this._file.url;
  1210. },
  1211.  
  1212.  
  1213. contentType: function()
  1214. {
  1215. return this._file.resourceType;
  1216. },
  1217.  
  1218.  
  1219. requestContent: function(callback)
  1220. {
  1221. var size =   (this._metadata.size);
  1222. this._file.requestFileContent(true, 0, size, this._charset || "", this._fileContentReceived.bind(this, callback));
  1223. },
  1224.  
  1225.  
  1226. _fileContentReceived: function(callback, errorCode, content, base64Encoded, charset)
  1227. {
  1228. if (errorCode || !content) {
  1229. callback(null, false, "");
  1230. return;
  1231. }
  1232.  
  1233. this._charset = charset;
  1234. callback(content, false, this.contentType().canonicalMimeType());
  1235. },
  1236.  
  1237.  
  1238. searchInContent: function(query, caseSensitive, isRegex, callback)
  1239. {
  1240. setTimeout(callback.bind(null, []), 0);
  1241. },
  1242.  
  1243.  
  1244. updateMetadata: function(metadata)
  1245. {
  1246. if (this._metadata.modificationTime >= metadata.modificationTime)
  1247. return false;
  1248. this._metadata = metadata.modificationTime;
  1249. return true;
  1250. }
  1251. }
  1252. ;
  1253.  
  1254.  
  1255.  
  1256. WebInspector.FileSystemView = function(fileSystem)
  1257. {
  1258. WebInspector.SidebarView.call(this, WebInspector.SidebarView.SidebarPosition.Left, "FileSystemViewSidebarWidth");
  1259. this.element.addStyleClass("file-system-view");
  1260. this.element.addStyleClass("storage-view");
  1261.  
  1262. var directoryTreeElement = this.element.createChild("ol", "filesystem-directory-tree");
  1263. this._directoryTree = new TreeOutline(directoryTreeElement);
  1264. this.sidebarElement.appendChild(directoryTreeElement);
  1265. this.sidebarElement.addStyleClass("outline-disclosure");
  1266. this.sidebarElement.addStyleClass("sidebar");
  1267.  
  1268. var rootItem = new WebInspector.FileSystemView.EntryTreeElement(this, fileSystem.root);
  1269. rootItem.expanded = true;
  1270. this._directoryTree.appendChild(rootItem);
  1271. this._visibleView = null;
  1272.  
  1273. this._refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
  1274. this._refreshButton.visible = true;
  1275. this._refreshButton.addEventListener("click", this._refresh, this);
  1276.  
  1277. this._deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
  1278. this._deleteButton.visible = true;
  1279. this._deleteButton.addEventListener("click", this._confirmDelete, this);
  1280. }
  1281.  
  1282. WebInspector.FileSystemView.prototype = {
  1283.  
  1284. get statusBarItems()
  1285. {
  1286. return [this._refreshButton.element, this._deleteButton.element];
  1287. },
  1288.  
  1289.  
  1290. get visibleView()
  1291. {
  1292. return this._visibleView;
  1293. },
  1294.  
  1295.  
  1296. showView: function(view)
  1297. {
  1298. if (this._visibleView === view)
  1299. return;
  1300. if (this._visibleView)
  1301. this._visibleView.detach();
  1302. this._visibleView = view;
  1303. view.show(this.mainElement);
  1304. },
  1305.  
  1306. _refresh: function()
  1307. {
  1308. this._directoryTree.children[0].refresh();
  1309. },
  1310.  
  1311. _confirmDelete: function()
  1312. {
  1313. if (confirm(WebInspector.UIString("Are you sure you want to delete the selected entry?")))
  1314. this._delete();
  1315. },
  1316.  
  1317. _delete: function()
  1318. {
  1319. this._directoryTree.selectedTreeElement.deleteEntry();
  1320. },
  1321.  
  1322. __proto__: WebInspector.SidebarView.prototype
  1323. }
  1324.  
  1325.  
  1326. WebInspector.FileSystemView.EntryTreeElement = function(fileSystemView, entry)
  1327. {
  1328. TreeElement.call(this, entry.name, null, entry.isDirectory);
  1329.  
  1330. this._entry = entry;
  1331. this._fileSystemView = fileSystemView;
  1332. }
  1333.  
  1334. WebInspector.FileSystemView.EntryTreeElement.prototype = {
  1335. onattach: function()
  1336. {
  1337. var selection = this.listItemElement.createChild("div", "selection");
  1338. this.listItemElement.insertBefore(selection, this.listItemElement.firstChild);
  1339. },
  1340.  
  1341. onselect: function()
  1342. {
  1343. if (!this._view) {
  1344. if (this._entry.isDirectory)
  1345. this._view = new WebInspector.DirectoryContentView();
  1346. else {
  1347. var file =   (this._entry);
  1348. this._view = new WebInspector.FileContentView(file);
  1349. }
  1350. }
  1351. this._fileSystemView.showView(this._view);
  1352. this.refresh();
  1353. },
  1354.  
  1355. onpopulate: function()
  1356. {
  1357. this.refresh();
  1358. },
  1359.  
  1360.  
  1361. _directoryContentReceived: function(errorCode, entries)
  1362. {
  1363. if (errorCode === FileError.NOT_FOUND_ERR) {
  1364. if (this.parent !== this.treeOutline)
  1365. this.parent.refresh();
  1366. return;
  1367. }
  1368.  
  1369. if (errorCode !== 0 || !entries) {
  1370. console.error("Failed to read directory: " + errorCode);
  1371. return;
  1372. }
  1373.  
  1374. entries.sort(WebInspector.FileSystemModel.Entry.compare);
  1375. if (this._view)
  1376. this._view.showEntries(entries);
  1377.  
  1378. var oldChildren = this.children.slice(0);
  1379.  
  1380. var newEntryIndex = 0;
  1381. var oldChildIndex = 0;
  1382. var currentTreeItem = 0;
  1383. while (newEntryIndex < entries.length && oldChildIndex < oldChildren.length) {
  1384. var newEntry = entries[newEntryIndex];
  1385. var oldChild = oldChildren[oldChildIndex];
  1386. var order = newEntry.name.localeCompare(oldChild._entry.name);
  1387.  
  1388. if (order === 0) {
  1389. if (oldChild._entry.isDirectory)
  1390. oldChild.shouldRefreshChildren = true;
  1391. else
  1392. oldChild.refresh();
  1393.  
  1394. ++newEntryIndex;
  1395. ++oldChildIndex;
  1396. ++currentTreeItem;
  1397. continue;
  1398. }
  1399. if (order < 0) {
  1400. this.insertChild(new WebInspector.FileSystemView.EntryTreeElement(this._fileSystemView, newEntry), currentTreeItem);
  1401. ++newEntryIndex;
  1402. ++currentTreeItem;
  1403. continue;
  1404. }
  1405.  
  1406. this.removeChildAtIndex(currentTreeItem);
  1407. ++oldChildIndex;
  1408. }
  1409. for (; newEntryIndex < entries.length; ++newEntryIndex)
  1410. this.appendChild(new WebInspector.FileSystemView.EntryTreeElement(this._fileSystemView, entries[newEntryIndex]));
  1411.  
  1412. for (; oldChildIndex < oldChildren.length; ++oldChildIndex)
  1413. this.removeChild(oldChildren[oldChildIndex]);
  1414. },
  1415.  
  1416. refresh: function()
  1417. {
  1418. if (!this._entry.isDirectory) {
  1419. if (this._view && this._view === this._fileSystemView.visibleView) {
  1420. var fileContentView =   (this._view);
  1421. fileContentView.refresh();
  1422. }
  1423. } else
  1424. this._entry.requestDirectoryContent(this._directoryContentReceived.bind(this));
  1425. },
  1426.  
  1427. deleteEntry: function()
  1428. {
  1429. this._entry.deleteEntry(this._deletionCompleted.bind(this));
  1430. },
  1431.  
  1432. _deletionCompleted: function()
  1433. {
  1434. if (this._entry != this._entry.fileSystem.root)
  1435. this.parent.refresh();
  1436. },
  1437.  
  1438. __proto__: TreeElement.prototype
  1439. }
  1440. ;
  1441.  
  1442.  
  1443. WebInspector.ResourcesPanel = function(database)
  1444. {
  1445. WebInspector.Panel.call(this, "resources");
  1446. this.registerRequiredCSS("resourcesPanel.css");
  1447.  
  1448. WebInspector.settings.resourcesLastSelectedItem = WebInspector.settings.createSetting("resourcesLastSelectedItem", {});
  1449.  
  1450. this.createSidebarViewWithTree();
  1451. this.sidebarElement.addStyleClass("outline-disclosure");
  1452. this.sidebarElement.addStyleClass("filter-all");
  1453. this.sidebarElement.addStyleClass("children");
  1454. this.sidebarElement.addStyleClass("small");
  1455.  
  1456. this.sidebarTreeElement.removeStyleClass("sidebar-tree");
  1457.  
  1458. this.resourcesListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Frames"), "Frames", ["frame-storage-tree-item"]);
  1459. this.sidebarTree.appendChild(this.resourcesListTreeElement);
  1460.  
  1461. this.databasesListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Web SQL"), "Databases", ["database-storage-tree-item"]);
  1462. this.sidebarTree.appendChild(this.databasesListTreeElement);
  1463.  
  1464. this.indexedDBListTreeElement = new WebInspector.IndexedDBTreeElement(this);
  1465. this.sidebarTree.appendChild(this.indexedDBListTreeElement);
  1466.  
  1467. this.localStorageListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Local Storage"), "LocalStorage", ["domstorage-storage-tree-item", "local-storage"]);
  1468. this.sidebarTree.appendChild(this.localStorageListTreeElement);
  1469.  
  1470. this.sessionStorageListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Session Storage"), "SessionStorage", ["domstorage-storage-tree-item", "session-storage"]);
  1471. this.sidebarTree.appendChild(this.sessionStorageListTreeElement);
  1472.  
  1473. this.cookieListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Cookies"), "Cookies", ["cookie-storage-tree-item"]);
  1474. this.sidebarTree.appendChild(this.cookieListTreeElement);
  1475.  
  1476. this.applicationCacheListTreeElement = new WebInspector.StorageCategoryTreeElement(this, WebInspector.UIString("Application Cache"), "ApplicationCache", ["application-cache-storage-tree-item"]);
  1477. this.sidebarTree.appendChild(this.applicationCacheListTreeElement);
  1478.  
  1479. if (Preferences.exposeFileSystemInspection && WebInspector.experimentsSettings.fileSystemInspection.isEnabled()) {
  1480. this.fileSystemListTreeElement = new WebInspector.FileSystemListTreeElement(this);
  1481. this.sidebarTree.appendChild(this.fileSystemListTreeElement);
  1482. }
  1483.  
  1484. this.storageViews = this.splitView.mainElement;
  1485. this.storageViews.addStyleClass("diff-container");
  1486.  
  1487. this.storageViewStatusBarItemsContainer = document.createElement("div");
  1488. this.storageViewStatusBarItemsContainer.className = "status-bar-items";
  1489.  
  1490. this._databaseTableViews = new Map();
  1491. this._databaseQueryViews = new Map();
  1492. this._databaseTreeElements = new Map();
  1493. this._domStorageViews = new Map();
  1494. this._domStorageTreeElements = new Map();
  1495. this._cookieViews = {};
  1496. this._origins = {};
  1497. this._domains = {};
  1498.  
  1499. this.sidebarElement.addEventListener("mousemove", this._onmousemove.bind(this), false);
  1500. this.sidebarElement.addEventListener("mouseout", this._onmouseout.bind(this), false);
  1501.  
  1502. function viewGetter()
  1503. {
  1504. return this.visibleView;
  1505. }
  1506. WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
  1507.  
  1508. if (WebInspector.resourceTreeModel.cachedResourcesLoaded())
  1509. this._cachedResourcesLoaded();
  1510.  
  1511. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._onLoadEventFired, this);
  1512. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded, this._cachedResourcesLoaded, this);
  1513. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.WillLoadCachedResources, this._resetWithFrames, this);
  1514.  
  1515. WebInspector.databaseModel.databases().forEach(this._addDatabase.bind(this));
  1516. WebInspector.databaseModel.addEventListener(WebInspector.DatabaseModel.Events.DatabaseAdded, this._databaseAdded, this);
  1517.  
  1518. WebInspector.domStorageModel.storages().forEach(this._addDOMStorage.bind(this));
  1519. WebInspector.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOMStorageAdded, this._domStorageAdded, this);
  1520. WebInspector.domStorageModel.addEventListener(WebInspector.DOMStorageModel.Events.DOMStorageUpdated, this._domStorageUpdated, this);
  1521. }
  1522.  
  1523. WebInspector.ResourcesPanel.prototype = {
  1524. get statusBarItems()
  1525. {
  1526. return [this.storageViewStatusBarItemsContainer];
  1527. },
  1528.  
  1529. wasShown: function()
  1530. {
  1531. WebInspector.Panel.prototype.wasShown.call(this);
  1532. this._initialize();
  1533. },
  1534.  
  1535. _initialize: function()
  1536. {
  1537. if (!this._initialized && this.isShowing() && this._cachedResourcesWereLoaded) {
  1538. this._populateResourceTree();
  1539. this._populateApplicationCacheTree();
  1540. this._initDefaultSelection();
  1541. this._initialized = true;
  1542. }
  1543. },
  1544.  
  1545. _onLoadEventFired: function()
  1546. {
  1547. this._initDefaultSelection();
  1548. },
  1549.  
  1550. _initDefaultSelection: function()
  1551. {
  1552. if (!this._initialized)
  1553. return;
  1554.  
  1555. var itemURL = WebInspector.settings.resourcesLastSelectedItem.get();
  1556. if (itemURL) {
  1557. for (var treeElement = this.sidebarTree.children[0]; treeElement; treeElement = treeElement.traverseNextTreeElement(false, this.sidebarTree, true)) {
  1558. if (treeElement.itemURL === itemURL) {
  1559. treeElement.revealAndSelect(true);
  1560. return;
  1561. }
  1562. }
  1563. }
  1564.  
  1565. var mainResource = WebInspector.inspectedPageURL && this.resourcesListTreeElement && this.resourcesListTreeElement.expanded && WebInspector.resourceTreeModel.resourceForURL(WebInspector.inspectedPageURL);
  1566. if (mainResource)
  1567. this.showResource(mainResource);
  1568. },
  1569.  
  1570. _resetWithFrames: function()
  1571. {
  1572. this.resourcesListTreeElement.removeChildren();
  1573. this._treeElementForFrameId = {};
  1574. this._reset();
  1575. },
  1576.  
  1577. _reset: function()
  1578. {
  1579. this._origins = {};
  1580. this._domains = {};
  1581. var queryViews = this._databaseQueryViews.values();
  1582. for (var i = 0; i < queryViews.length; ++i)
  1583. queryViews[i].removeEventListener(WebInspector.DatabaseQueryView.Events.SchemaUpdated, this._updateDatabaseTables, this);
  1584. this._databaseTableViews.clear();
  1585. this._databaseQueryViews.clear();
  1586. this._databaseTreeElements.clear();
  1587. this._domStorageViews.clear();
  1588. this._domStorageTreeElements.clear();
  1589. this._cookieViews = {};
  1590.  
  1591. this.databasesListTreeElement.removeChildren();
  1592. this.localStorageListTreeElement.removeChildren();
  1593. this.sessionStorageListTreeElement.removeChildren();
  1594. this.cookieListTreeElement.removeChildren();
  1595.  
  1596. if (this.visibleView)
  1597. this.visibleView.detach();
  1598.  
  1599. this.storageViewStatusBarItemsContainer.removeChildren();
  1600.  
  1601. if (this.sidebarTree.selectedTreeElement)
  1602. this.sidebarTree.selectedTreeElement.deselect();
  1603. },
  1604.  
  1605. _populateResourceTree: function()
  1606. {
  1607. this._treeElementForFrameId = {};
  1608. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
  1609. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  1610. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
  1611. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
  1612.  
  1613. function populateFrame(frame)
  1614. {
  1615. this._frameAdded({data:frame});
  1616. for (var i = 0; i < frame.childFrames.length; ++i)
  1617. populateFrame.call(this, frame.childFrames[i]);
  1618.  
  1619. var resources = frame.resources();
  1620. for (var i = 0; i < resources.length; ++i)
  1621. this._resourceAdded({data:resources[i]});
  1622. }
  1623. populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
  1624. },
  1625.  
  1626. _frameAdded: function(event)
  1627. {
  1628. var frame = event.data;
  1629. var parentFrame = frame.parentFrame;
  1630.  
  1631. var parentTreeElement = parentFrame ? this._treeElementForFrameId[parentFrame.id] : this.resourcesListTreeElement;
  1632. if (!parentTreeElement) {
  1633. console.warn("No frame to route " + frame.url + " to.")
  1634. return;
  1635. }
  1636.  
  1637. var frameTreeElement = new WebInspector.FrameTreeElement(this, frame);
  1638. this._treeElementForFrameId[frame.id] = frameTreeElement;
  1639. parentTreeElement.appendChild(frameTreeElement);
  1640. },
  1641.  
  1642. _frameDetached: function(event)
  1643. {
  1644. var frame = event.data;
  1645. var frameTreeElement = this._treeElementForFrameId[frame.id];
  1646. if (!frameTreeElement)
  1647. return;
  1648.  
  1649. delete this._treeElementForFrameId[frame.id];
  1650. if (frameTreeElement.parent)
  1651. frameTreeElement.parent.removeChild(frameTreeElement);
  1652. },
  1653.  
  1654. _resourceAdded: function(event)
  1655. {
  1656. var resource = event.data;
  1657. var frameId = resource.frameId;
  1658.  
  1659. if (resource.statusCode >= 301 && resource.statusCode <= 303)
  1660. return;
  1661.  
  1662. var frameTreeElement = this._treeElementForFrameId[frameId];
  1663. if (!frameTreeElement) {
  1664.  
  1665.  
  1666. return;
  1667. }
  1668.  
  1669. frameTreeElement.appendResource(resource);
  1670. },
  1671.  
  1672. _frameNavigated: function(event)
  1673. {
  1674. var frame = event.data;
  1675.  
  1676. if (!frame.parentFrame)
  1677. this._reset();
  1678.  
  1679. var frameId = frame.id;
  1680. var frameTreeElement = this._treeElementForFrameId[frameId];
  1681. if (frameTreeElement)
  1682. frameTreeElement.frameNavigated(frame);
  1683.  
  1684. var applicationCacheFrameTreeElement = this._applicationCacheFrameElements[frameId];
  1685. if (applicationCacheFrameTreeElement)
  1686. applicationCacheFrameTreeElement.frameNavigated(frame);
  1687. },
  1688.  
  1689. _cachedResourcesLoaded: function()
  1690. {
  1691. this._cachedResourcesWereLoaded = true;
  1692. this._initialize();
  1693. },
  1694.  
  1695.  
  1696. _databaseAdded: function(event)
  1697. {
  1698. var database =   (event.data);
  1699. this._addDatabase(database);
  1700. },
  1701.  
  1702.  
  1703. _addDatabase: function(database)
  1704. {
  1705. var databaseTreeElement = new WebInspector.DatabaseTreeElement(this, database);
  1706. this._databaseTreeElements.put(database, databaseTreeElement);
  1707. this.databasesListTreeElement.appendChild(databaseTreeElement);
  1708. },
  1709.  
  1710. addDocumentURL: function(url)
  1711. {
  1712. var parsedURL = url.asParsedURL();
  1713. if (!parsedURL)
  1714. return;
  1715.  
  1716. var domain = parsedURL.host;
  1717. if (!this._domains[domain]) {
  1718. this._domains[domain] = true;
  1719.  
  1720. var cookieDomainTreeElement = new WebInspector.CookieTreeElement(this, domain);
  1721. this.cookieListTreeElement.appendChild(cookieDomainTreeElement);
  1722. }
  1723. },
  1724.  
  1725.  
  1726. _domStorageAdded: function(event)
  1727. {
  1728. var domStorage =   (event.data);
  1729. this._addDOMStorage(domStorage);
  1730. },
  1731.  
  1732.  
  1733. _addDOMStorage: function(domStorage)
  1734. {
  1735. var domStorageTreeElement = new WebInspector.DOMStorageTreeElement(this, domStorage, (domStorage.isLocalStorage ? "local-storage" : "session-storage"));
  1736. this._domStorageTreeElements.put(domStorage, domStorageTreeElement);
  1737. if (domStorage.isLocalStorage)
  1738. this.localStorageListTreeElement.appendChild(domStorageTreeElement);
  1739. else
  1740. this.sessionStorageListTreeElement.appendChild(domStorageTreeElement);
  1741. },
  1742.  
  1743.  
  1744. selectDatabase: function(database)
  1745. {
  1746. if (database) {
  1747. this._showDatabase(database);
  1748. this._databaseTreeElements.get(database).select();
  1749. }
  1750. },
  1751.  
  1752.  
  1753. selectDOMStorage: function(domStorage)
  1754. {
  1755. if (domStorage) {
  1756. this._showDOMStorage(domStorage);
  1757. this._domStorageTreeElements.get(domStorage).select();
  1758. }
  1759. },
  1760.  
  1761. canShowAnchorLocation: function(anchor)
  1762. {
  1763. return !!WebInspector.resourceForURL(anchor.href);
  1764. },
  1765.  
  1766. showAnchorLocation: function(anchor)
  1767. {
  1768. var resource = WebInspector.resourceForURL(anchor.href);
  1769. this.showResource(resource, anchor.lineNumber);
  1770. },
  1771.  
  1772.  
  1773. showResource: function(resource, line)
  1774. {
  1775. var resourceTreeElement = this._findTreeElementForResource(resource);
  1776. if (resourceTreeElement)
  1777. resourceTreeElement.revealAndSelect();
  1778.  
  1779. if (typeof line === "number") {
  1780. var view = this._resourceViewForResource(resource);
  1781. if (view.canHighlightLine())
  1782. view.highlightLine(line);
  1783. }
  1784. return true;
  1785. },
  1786.  
  1787. _showResourceView: function(resource)
  1788. {
  1789. var view = this._resourceViewForResource(resource);
  1790. if (!view) {
  1791. this.visibleView.detach();
  1792. return;
  1793. }
  1794. if (view.searchCanceled)
  1795. view.searchCanceled();
  1796. this._innerShowView(view);
  1797. },
  1798.  
  1799. _resourceViewForResource: function(resource)
  1800. {
  1801. if (WebInspector.ResourceView.hasTextContent(resource)) {
  1802. var treeElement = this._findTreeElementForResource(resource);
  1803. if (!treeElement)
  1804. return null;
  1805. return treeElement.sourceView();
  1806. }
  1807. return WebInspector.ResourceView.nonSourceViewForResource(resource);
  1808. },
  1809.  
  1810.  
  1811. _showDatabase: function(database, tableName)
  1812. {
  1813. if (!database)
  1814. return;
  1815.  
  1816. var view;
  1817. if (tableName) {
  1818. var tableViews = this._databaseTableViews.get(database);
  1819. if (!tableViews) {
  1820. tableViews = {};
  1821. this._databaseTableViews.put(database, tableViews);
  1822. }
  1823. view = tableViews[tableName];
  1824. if (!view) {
  1825. view = new WebInspector.DatabaseTableView(database, tableName);
  1826. tableViews[tableName] = view;
  1827. }
  1828. } else {
  1829. view = this._databaseQueryViews.get(database);
  1830. if (!view) {
  1831. view = new WebInspector.DatabaseQueryView(database);
  1832. this._databaseQueryViews.put(database, view);
  1833. view.addEventListener(WebInspector.DatabaseQueryView.Events.SchemaUpdated, this._updateDatabaseTables, this);
  1834. }
  1835. }
  1836.  
  1837. this._innerShowView(view);
  1838. },
  1839.  
  1840.  
  1841. showIndexedDB: function(view)
  1842. {
  1843. this._innerShowView(view);
  1844. },
  1845.  
  1846. _showDOMStorage: function(domStorage)
  1847. {
  1848. if (!domStorage)
  1849. return;
  1850.  
  1851. var view;
  1852. view = this._domStorageViews.get(domStorage);
  1853. if (!view) {
  1854. view = new WebInspector.DOMStorageItemsView(domStorage);
  1855. this._domStorageViews.put(domStorage, view);
  1856. }
  1857.  
  1858. this._innerShowView(view);
  1859. },
  1860.  
  1861. showCookies: function(treeElement, cookieDomain)
  1862. {
  1863. var view = this._cookieViews[cookieDomain];
  1864. if (!view) {
  1865. view = new WebInspector.CookieItemsView(treeElement, cookieDomain);
  1866. this._cookieViews[cookieDomain] = view;
  1867. }
  1868.  
  1869. this._innerShowView(view);
  1870. },
  1871.  
  1872. showApplicationCache: function(frameId)
  1873. {
  1874. if (!this._applicationCacheViews[frameId])
  1875. this._applicationCacheViews[frameId] = new WebInspector.ApplicationCacheItemsView(this._applicationCacheModel, frameId);
  1876.  
  1877. this._innerShowView(this._applicationCacheViews[frameId]);
  1878. },
  1879.  
  1880.  
  1881. showFileSystem: function(view)
  1882. {
  1883. this._innerShowView(view);
  1884. },
  1885.  
  1886. showCategoryView: function(categoryName)
  1887. {
  1888. if (!this._categoryView)
  1889. this._categoryView = new WebInspector.StorageCategoryView();
  1890. this._categoryView.setText(categoryName);
  1891. this._innerShowView(this._categoryView);
  1892. },
  1893.  
  1894. _innerShowView: function(view)
  1895. {
  1896. if (this.visibleView === view)
  1897. return;
  1898.  
  1899. if (this.visibleView)
  1900. this.visibleView.detach();
  1901.  
  1902. view.show(this.storageViews);
  1903. this.visibleView = view;
  1904.  
  1905. this.storageViewStatusBarItemsContainer.removeChildren();
  1906. var statusBarItems = view.statusBarItems || [];
  1907. for (var i = 0; i < statusBarItems.length; ++i)
  1908. this.storageViewStatusBarItemsContainer.appendChild(statusBarItems[i]);
  1909. },
  1910.  
  1911. closeVisibleView: function()
  1912. {
  1913. if (!this.visibleView)
  1914. return;
  1915. this.visibleView.detach();
  1916. delete this.visibleView;
  1917. },
  1918.  
  1919. _updateDatabaseTables: function(event)
  1920. {
  1921. var database = event.data;
  1922.  
  1923. if (!database)
  1924. return;
  1925.  
  1926. var databasesTreeElement = this._databaseTreeElements.get(database);
  1927. if (!databasesTreeElement)
  1928. return;
  1929.  
  1930. databasesTreeElement.shouldRefreshChildren = true;
  1931. var tableViews = this._databaseTableViews.get(database);
  1932.  
  1933. if (!tableViews)
  1934. return;
  1935.  
  1936. var tableNamesHash = {};
  1937. var self = this;
  1938. function tableNamesCallback(tableNames)
  1939. {
  1940. var tableNamesLength = tableNames.length;
  1941. for (var i = 0; i < tableNamesLength; ++i)
  1942. tableNamesHash[tableNames[i]] = true;
  1943.  
  1944. for (var tableName in tableViews) {
  1945. if (!(tableName in tableNamesHash)) {
  1946. if (self.visibleView === tableViews[tableName])
  1947. self.closeVisibleView();
  1948. delete tableViews[tableName];
  1949. }
  1950. }
  1951. }
  1952. database.getTableNames(tableNamesCallback);
  1953. },
  1954.  
  1955.  
  1956. _domStorageUpdated: function(event)
  1957. {
  1958. var storage =   (event.data);
  1959. var view = this._domStorageViews.get(storage);
  1960. if (this.visibleView && view === this.visibleView)
  1961. view.update();
  1962. },
  1963.  
  1964. _populateApplicationCacheTree: function()
  1965. {
  1966. this._applicationCacheModel = new WebInspector.ApplicationCacheModel();
  1967.  
  1968. this._applicationCacheViews = {};
  1969. this._applicationCacheFrameElements = {};
  1970. this._applicationCacheManifestElements = {};
  1971.  
  1972. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestAdded, this._applicationCacheFrameManifestAdded, this);
  1973. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestRemoved, this._applicationCacheFrameManifestRemoved, this);
  1974.  
  1975. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestStatusUpdated, this._applicationCacheFrameManifestStatusChanged, this);
  1976. this._applicationCacheModel.addEventListener(WebInspector.ApplicationCacheModel.EventTypes.NetworkStateChanged, this._applicationCacheNetworkStateChanged, this);
  1977. },
  1978.  
  1979. _applicationCacheFrameManifestAdded: function(event)
  1980. {
  1981. var frameId = event.data;
  1982. var manifestURL = this._applicationCacheModel.frameManifestURL(frameId);
  1983. var status = this._applicationCacheModel.frameManifestStatus(frameId)
  1984.  
  1985. var manifestTreeElement = this._applicationCacheManifestElements[manifestURL]
  1986. if (!manifestTreeElement) {
  1987. manifestTreeElement = new WebInspector.ApplicationCacheManifestTreeElement(this, manifestURL);
  1988. this.applicationCacheListTreeElement.appendChild(manifestTreeElement);
  1989. this._applicationCacheManifestElements[manifestURL] = manifestTreeElement;
  1990. }
  1991.  
  1992. var frameTreeElement = new WebInspector.ApplicationCacheFrameTreeElement(this, frameId, manifestURL);
  1993. manifestTreeElement.appendChild(frameTreeElement);
  1994. manifestTreeElement.expand();
  1995. this._applicationCacheFrameElements[frameId] = frameTreeElement;
  1996. },
  1997.  
  1998. _applicationCacheFrameManifestRemoved: function(event)
  1999. {
  2000. var frameId = event.data;
  2001. var frameTreeElement = this._applicationCacheFrameElements[frameId];
  2002. if (!frameTreeElement)
  2003. return;
  2004.  
  2005. var manifestURL = frameTreeElement.manifestURL;
  2006. delete this._applicationCacheFrameElements[frameId];
  2007. delete this._applicationCacheViews[frameId];
  2008. frameTreeElement.parent.removeChild(frameTreeElement);
  2009.  
  2010. var manifestTreeElement = this._applicationCacheManifestElements[manifestURL];
  2011. if (manifestTreeElement.children.length !== 0)
  2012. return;
  2013.  
  2014. delete this._applicationCacheManifestElements[manifestURL];
  2015. manifestTreeElement.parent.removeChild(manifestTreeElement);
  2016. },
  2017.  
  2018. _applicationCacheFrameManifestStatusChanged: function(event)
  2019. {
  2020. var frameId = event.data;
  2021. var status = this._applicationCacheModel.frameManifestStatus(frameId)
  2022.  
  2023. if (this._applicationCacheViews[frameId])
  2024. this._applicationCacheViews[frameId].updateStatus(status);
  2025. },
  2026.  
  2027. _applicationCacheNetworkStateChanged: function(event)
  2028. {
  2029. var isNowOnline = event.data;
  2030.  
  2031. for (var manifestURL in this._applicationCacheViews)
  2032. this._applicationCacheViews[manifestURL].updateNetworkState(isNowOnline);
  2033. },
  2034.  
  2035. sidebarResized: function(event)
  2036. {
  2037. var width = event.data;
  2038. this.storageViewStatusBarItemsContainer.style.left = width + "px";
  2039. },
  2040.  
  2041.  
  2042. performSearch: function(query)
  2043. {
  2044. this._resetSearchResults();
  2045. var regex = WebInspector.SourceFrame.createSearchRegex(query);
  2046. var totalMatchesCount = 0;
  2047.  
  2048. function callback(error, result)
  2049. {
  2050. if (!error) {
  2051. for (var i = 0; i < result.length; i++) {
  2052. var searchResult = result[i];
  2053. var frameTreeElement = this._treeElementForFrameId[searchResult.frameId];
  2054. if (!frameTreeElement)
  2055. continue;
  2056. var resource = frameTreeElement.resourceByURL(searchResult.url);
  2057.  
  2058.  
  2059.  
  2060.  
  2061. if (!resource)
  2062. continue;
  2063.  
  2064. this._findTreeElementForResource(resource).searchMatchesFound(searchResult.matchesCount);
  2065. totalMatchesCount += searchResult.matchesCount;
  2066. }
  2067. }
  2068.  
  2069. WebInspector.searchController.updateSearchMatchesCount(totalMatchesCount, this);
  2070. this._searchController = new WebInspector.ResourcesSearchController(this.resourcesListTreeElement, totalMatchesCount);
  2071.  
  2072. if (this.sidebarTree.selectedTreeElement && this.sidebarTree.selectedTreeElement.searchMatchesCount)
  2073. this.jumpToNextSearchResult();
  2074. }
  2075.  
  2076. PageAgent.searchInResources(regex.source, !regex.ignoreCase, true, callback.bind(this));
  2077. },
  2078.  
  2079. _ensureViewSearchPerformed: function(callback)
  2080. {
  2081. function viewSearchPerformedCallback(searchId)
  2082. {
  2083. if (searchId !== this._lastViewSearchId)
  2084. return; 
  2085. this._viewSearchInProgress = false;
  2086. callback();
  2087. }
  2088.  
  2089. if (!this._viewSearchInProgress) {
  2090. if (!this.visibleView.hasSearchResults()) {
  2091.  
  2092. this._lastViewSearchId = this._lastViewSearchId ? this._lastViewSearchId + 1 : 0;
  2093. this._viewSearchInProgress = true;
  2094. this.visibleView.performSearch(this.currentQuery, viewSearchPerformedCallback.bind(this, this._lastViewSearchId));
  2095. } else
  2096. callback();
  2097. }
  2098. },
  2099.  
  2100. _showSearchResult: function(searchResult)
  2101. {
  2102. this._lastSearchResultIndex = searchResult.index;
  2103. this._lastSearchResultTreeElement = searchResult.treeElement;
  2104.  
  2105.  
  2106. if (searchResult.treeElement !== this.sidebarTree.selectedTreeElement) {
  2107. this.showResource(searchResult.treeElement.representedObject);
  2108. WebInspector.searchController.showSearchField();
  2109. }
  2110.  
  2111. function callback(searchId)
  2112. {
  2113. if (this.sidebarTree.selectedTreeElement !== this._lastSearchResultTreeElement)
  2114. return; 
  2115. if (this._lastSearchResultIndex != -1)
  2116. this.visibleView.jumpToSearchResult(this._lastSearchResultIndex);
  2117. WebInspector.searchController.updateCurrentMatchIndex(searchResult.currentMatchIndex - 1, this);
  2118. }
  2119.  
  2120.  
  2121. this._ensureViewSearchPerformed(callback.bind(this));
  2122. },
  2123.  
  2124. _resetSearchResults: function()
  2125. {
  2126. function callback(resourceTreeElement)
  2127. {
  2128. resourceTreeElement._resetSearchResults();
  2129. }
  2130.  
  2131. this._forAllResourceTreeElements(callback);
  2132. if (this.visibleView && this.visibleView.searchCanceled)
  2133. this.visibleView.searchCanceled();
  2134.  
  2135. this._lastSearchResultTreeElement = null;
  2136. this._lastSearchResultIndex = -1;
  2137. this._viewSearchInProgress = false;
  2138. },
  2139.  
  2140. searchCanceled: function()
  2141. {
  2142. function callback(resourceTreeElement)
  2143. {
  2144. resourceTreeElement._updateErrorsAndWarningsBubbles();
  2145. }
  2146.  
  2147. WebInspector.searchController.updateSearchMatchesCount(0, this);
  2148. this._resetSearchResults();
  2149. this._forAllResourceTreeElements(callback);
  2150. },
  2151.  
  2152. jumpToNextSearchResult: function()
  2153. {
  2154. if (!this.currentSearchMatches)
  2155. return;
  2156. var currentTreeElement = this.sidebarTree.selectedTreeElement;
  2157. var nextSearchResult = this._searchController.nextSearchResult(currentTreeElement);
  2158. this._showSearchResult(nextSearchResult);
  2159. },
  2160.  
  2161. jumpToPreviousSearchResult: function()
  2162. {
  2163. if (!this.currentSearchMatches)
  2164. return;
  2165. var currentTreeElement = this.sidebarTree.selectedTreeElement;
  2166. var previousSearchResult = this._searchController.previousSearchResult(currentTreeElement);
  2167. this._showSearchResult(previousSearchResult);
  2168. },
  2169.  
  2170. _forAllResourceTreeElements: function(callback)
  2171. {
  2172. var stop = false;
  2173. for (var treeElement = this.resourcesListTreeElement; !stop && treeElement; treeElement = treeElement.traverseNextTreeElement(false, this.resourcesListTreeElement, true)) {
  2174. if (treeElement instanceof WebInspector.FrameResourceTreeElement)
  2175. stop = callback(treeElement);
  2176. }
  2177. },
  2178.  
  2179. _findTreeElementForResource: function(resource)
  2180. {
  2181. function isAncestor(ancestor, object)
  2182. {
  2183.  
  2184. return false;
  2185. }
  2186.  
  2187. function getParent(object)
  2188. {
  2189.  
  2190. return null;
  2191. }
  2192.  
  2193. return this.sidebarTree.findTreeElement(resource, isAncestor, getParent);
  2194. },
  2195.  
  2196. showView: function(view)
  2197. {
  2198. if (view)
  2199. this.showResource(view.resource);
  2200. },
  2201.  
  2202. _onmousemove: function(event)
  2203. {
  2204. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  2205. if (!nodeUnderMouse)
  2206. return;
  2207.  
  2208. var listNode = nodeUnderMouse.enclosingNodeOrSelfWithNodeName("li");
  2209. if (!listNode)
  2210. return;
  2211.  
  2212. var element = listNode.treeElement;
  2213. if (this._previousHoveredElement === element)
  2214. return;
  2215.  
  2216. if (this._previousHoveredElement) {
  2217. this._previousHoveredElement.hovered = false;
  2218. delete this._previousHoveredElement;
  2219. }
  2220.  
  2221. if (element instanceof WebInspector.FrameTreeElement) {
  2222. this._previousHoveredElement = element;
  2223. element.hovered = true;
  2224. }
  2225. },
  2226.  
  2227. _onmouseout: function(event)
  2228. {
  2229. if (this._previousHoveredElement) {
  2230. this._previousHoveredElement.hovered = false;
  2231. delete this._previousHoveredElement;
  2232. }
  2233. },
  2234.  
  2235. __proto__: WebInspector.Panel.prototype
  2236. }
  2237.  
  2238.  
  2239. WebInspector.BaseStorageTreeElement = function(storagePanel, representedObject, title, iconClasses, hasChildren, noIcon)
  2240. {
  2241. TreeElement.call(this, "", representedObject, hasChildren);
  2242. this._storagePanel = storagePanel;
  2243. this._titleText = title;
  2244. this._iconClasses = iconClasses;
  2245. this._noIcon = noIcon;
  2246. }
  2247.  
  2248. WebInspector.BaseStorageTreeElement.prototype = {
  2249. onattach: function()
  2250. {
  2251. this.listItemElement.removeChildren();
  2252. if (this._iconClasses) {
  2253. for (var i = 0; i < this._iconClasses.length; ++i)
  2254. this.listItemElement.addStyleClass(this._iconClasses[i]);
  2255. }
  2256.  
  2257. var selectionElement = document.createElement("div");
  2258. selectionElement.className = "selection";
  2259. this.listItemElement.appendChild(selectionElement);
  2260.  
  2261. if (!this._noIcon) {
  2262. this.imageElement = document.createElement("img");
  2263. this.imageElement.className = "icon";
  2264. this.listItemElement.appendChild(this.imageElement);
  2265. }
  2266.  
  2267. this.titleElement = document.createElement("div");
  2268. this.titleElement.className = "base-storage-tree-element-title";
  2269. this._titleTextNode = document.createTextNode("");
  2270. this.titleElement.appendChild(this._titleTextNode);
  2271. this._updateTitle();
  2272. this._updateSubtitle();
  2273. this.listItemElement.appendChild(this.titleElement);
  2274. },
  2275.  
  2276. get displayName()
  2277. {
  2278. return this._displayName;
  2279. },
  2280.  
  2281. _updateDisplayName: function()
  2282. {
  2283. this._displayName = this._titleText || "";
  2284. if (this._subtitleText)
  2285. this._displayName += " (" + this._subtitleText + ")";
  2286. },
  2287.  
  2288. _updateTitle: function()
  2289. {
  2290. this._updateDisplayName();
  2291.  
  2292. if (!this.titleElement)
  2293. return;
  2294.  
  2295. this._titleTextNode.textContent = this._titleText || "";
  2296. },
  2297.  
  2298. _updateSubtitle: function()
  2299. {
  2300. this._updateDisplayName();
  2301.  
  2302. if (!this.titleElement)
  2303. return;
  2304.  
  2305. if (this._subtitleText) {
  2306. if (!this._subtitleElement) {
  2307. this._subtitleElement = document.createElement("span");
  2308. this._subtitleElement.className = "base-storage-tree-element-subtitle";
  2309. this.titleElement.appendChild(this._subtitleElement);
  2310. }
  2311. this._subtitleElement.textContent = "(" + this._subtitleText + ")";
  2312. } else if (this._subtitleElement) {
  2313. this.titleElement.removeChild(this._subtitleElement);
  2314. delete this._subtitleElement;
  2315. }
  2316. },
  2317.  
  2318. onselect: function()
  2319. {
  2320. var itemURL = this.itemURL;
  2321. if (itemURL)
  2322. WebInspector.settings.resourcesLastSelectedItem.set(itemURL);
  2323. },
  2324.  
  2325. onreveal: function()
  2326. {
  2327. if (this.listItemElement)
  2328. this.listItemElement.scrollIntoViewIfNeeded(false);
  2329. },
  2330.  
  2331. get titleText()
  2332. {
  2333. return this._titleText;
  2334. },
  2335.  
  2336. set titleText(titleText)
  2337. {
  2338. this._titleText = titleText;
  2339. this._updateTitle();
  2340. },
  2341.  
  2342. get subtitleText()
  2343. {
  2344. return this._subtitleText;
  2345. },
  2346.  
  2347. set subtitleText(subtitleText)
  2348. {
  2349. this._subtitleText = subtitleText;
  2350. this._updateSubtitle();
  2351. },
  2352.  
  2353. get searchMatchesCount()
  2354. {
  2355. return 0;
  2356. },
  2357.  
  2358. __proto__: TreeElement.prototype
  2359. }
  2360.  
  2361.  
  2362. WebInspector.StorageCategoryTreeElement = function(storagePanel, categoryName, settingsKey, iconClasses, noIcon)
  2363. {
  2364. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, categoryName, iconClasses, true, noIcon);
  2365. this._expandedSettingKey = "resources" + settingsKey + "Expanded";
  2366. WebInspector.settings[this._expandedSettingKey] = WebInspector.settings.createSetting(this._expandedSettingKey, settingsKey === "Frames");
  2367. this._categoryName = categoryName;
  2368. }
  2369.  
  2370. WebInspector.StorageCategoryTreeElement.prototype = {
  2371. get itemURL()
  2372. {
  2373. return "category://" + this._categoryName;
  2374. },
  2375.  
  2376. onselect: function()
  2377. {
  2378. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  2379. this._storagePanel.showCategoryView(this._categoryName);
  2380. },
  2381.  
  2382. onattach: function()
  2383. {
  2384. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  2385. if (WebInspector.settings[this._expandedSettingKey].get())
  2386. this.expand();
  2387. },
  2388.  
  2389. onexpand: function()
  2390. {
  2391. WebInspector.settings[this._expandedSettingKey].set(true);
  2392. },
  2393.  
  2394. oncollapse: function()
  2395. {
  2396. WebInspector.settings[this._expandedSettingKey].set(false);
  2397. },
  2398.  
  2399. __proto__: WebInspector.BaseStorageTreeElement.prototype
  2400. }
  2401.  
  2402.  
  2403. WebInspector.FrameTreeElement = function(storagePanel, frame)
  2404. {
  2405. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, "", ["frame-storage-tree-item"]);
  2406. this._frame = frame;
  2407. this.frameNavigated(frame);
  2408. }
  2409.  
  2410. WebInspector.FrameTreeElement.prototype = {
  2411. frameNavigated: function(frame)
  2412. {
  2413. this.removeChildren();
  2414. this._frameId = frame.id;
  2415.  
  2416. this.titleText = frame.name;
  2417. this.subtitleText = new WebInspector.ParsedURL(frame.url).displayName;
  2418.  
  2419. this._categoryElements = {};
  2420. this._treeElementForResource = {};
  2421.  
  2422. this._storagePanel.addDocumentURL(frame.url);
  2423. },
  2424.  
  2425. get itemURL()
  2426. {
  2427. return "frame://" + encodeURI(this.displayName);
  2428. },
  2429.  
  2430. onselect: function()
  2431. {
  2432. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  2433. this._storagePanel.showCategoryView(this.displayName);
  2434.  
  2435. this.listItemElement.removeStyleClass("hovered");
  2436. DOMAgent.hideHighlight();
  2437. },
  2438.  
  2439. set hovered(hovered)
  2440. {
  2441. if (hovered) {
  2442. this.listItemElement.addStyleClass("hovered");
  2443. DOMAgent.highlightFrame(this._frameId, WebInspector.Color.PageHighlight.Content.toProtocolRGBA(), WebInspector.Color.PageHighlight.ContentOutline.toProtocolRGBA());
  2444. } else {
  2445. this.listItemElement.removeStyleClass("hovered");
  2446. DOMAgent.hideHighlight();
  2447. }
  2448. },
  2449.  
  2450. appendResource: function(resource)
  2451. {
  2452. if (resource.isHidden())
  2453. return;
  2454. var categoryName = resource.type.name();
  2455. var categoryElement = resource.type === WebInspector.resourceTypes.Document ? this : this._categoryElements[categoryName];
  2456. if (!categoryElement) {
  2457. categoryElement = new WebInspector.StorageCategoryTreeElement(this._storagePanel, resource.type.categoryTitle(), categoryName, null, true);
  2458. this._categoryElements[resource.type.name()] = categoryElement;
  2459. this._insertInPresentationOrder(this, categoryElement);
  2460. }
  2461. var resourceTreeElement = new WebInspector.FrameResourceTreeElement(this._storagePanel, resource);
  2462. this._insertInPresentationOrder(categoryElement, resourceTreeElement);
  2463. this._treeElementForResource[resource.url] = resourceTreeElement;
  2464. },
  2465.  
  2466. resourceByURL: function(url)
  2467. {
  2468. var treeElement = this._treeElementForResource[url];
  2469. return treeElement ? treeElement.representedObject : null;
  2470. },
  2471.  
  2472. appendChild: function(treeElement)
  2473. {
  2474. this._insertInPresentationOrder(this, treeElement);
  2475. },
  2476.  
  2477. _insertInPresentationOrder: function(parentTreeElement, childTreeElement)
  2478. {
  2479.  
  2480. function typeWeight(treeElement)
  2481. {
  2482. if (treeElement instanceof WebInspector.StorageCategoryTreeElement)
  2483. return 2;
  2484. if (treeElement instanceof WebInspector.FrameTreeElement)
  2485. return 1;
  2486. return 3;
  2487. }
  2488.  
  2489. function compare(treeElement1, treeElement2)
  2490. {
  2491. var typeWeight1 = typeWeight(treeElement1);
  2492. var typeWeight2 = typeWeight(treeElement2);
  2493.  
  2494. var result;
  2495. if (typeWeight1 > typeWeight2)
  2496. result = 1;
  2497. else if (typeWeight1 < typeWeight2)
  2498. result = -1;
  2499. else {
  2500. var title1 = treeElement1.displayName || treeElement1.titleText;
  2501. var title2 = treeElement2.displayName || treeElement2.titleText;
  2502. result = title1.localeCompare(title2);
  2503. }
  2504. return result;
  2505. }
  2506.  
  2507. var children = parentTreeElement.children;
  2508. var i;
  2509. for (i = 0; i < children.length; ++i) {
  2510. if (compare(childTreeElement, children[i]) < 0)
  2511. break;
  2512. }
  2513. parentTreeElement.insertChild(childTreeElement, i);
  2514. },
  2515.  
  2516. __proto__: WebInspector.BaseStorageTreeElement.prototype
  2517. }
  2518.  
  2519.  
  2520. WebInspector.FrameResourceTreeElement = function(storagePanel, resource)
  2521. {
  2522. WebInspector.BaseStorageTreeElement.call(this, storagePanel, resource, resource.displayName, ["resource-sidebar-tree-item", "resources-type-" + resource.type.name()]);
  2523. this._resource = resource;
  2524. this._resource.addEventListener(WebInspector.Resource.Events.MessageAdded, this._consoleMessageAdded, this);
  2525. this._resource.addEventListener(WebInspector.Resource.Events.MessagesCleared, this._consoleMessagesCleared, this);
  2526. this.tooltip = resource.url;
  2527. }
  2528.  
  2529. WebInspector.FrameResourceTreeElement.prototype = {
  2530. get itemURL()
  2531. {
  2532. return this._resource.url;
  2533. },
  2534.  
  2535. onselect: function()
  2536. {
  2537. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  2538. this._storagePanel._showResourceView(this._resource);
  2539. },
  2540.  
  2541. ondblclick: function(event)
  2542. {
  2543. InspectorFrontendHost.openInNewTab(this._resource.url);
  2544. },
  2545.  
  2546. onattach: function()
  2547. {
  2548. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  2549.  
  2550. if (this._resource.type === WebInspector.resourceTypes.Image) {
  2551. var previewImage = document.createElement("img");
  2552. previewImage.className = "image-resource-icon-preview";
  2553. this._resource.populateImageSource(previewImage);
  2554.  
  2555. var iconElement = document.createElement("div");
  2556. iconElement.className = "icon";
  2557. iconElement.appendChild(previewImage);
  2558. this.listItemElement.replaceChild(iconElement, this.imageElement);
  2559. }
  2560.  
  2561. this._statusElement = document.createElement("div");
  2562. this._statusElement.className = "status";
  2563. this.listItemElement.insertBefore(this._statusElement, this.titleElement);
  2564.  
  2565. this.listItemElement.draggable = true;
  2566. this.listItemElement.addEventListener("dragstart", this._ondragstart.bind(this), false);
  2567. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  2568.  
  2569. this._updateErrorsAndWarningsBubbles();
  2570. },
  2571.  
  2572. _ondragstart: function(event)
  2573. {
  2574. event.dataTransfer.setData("text/plain", this._resource.content);
  2575. event.dataTransfer.effectAllowed = "copy";
  2576. return true;
  2577. },
  2578.  
  2579. _handleContextMenuEvent: function(event)
  2580. {
  2581. var contextMenu = new WebInspector.ContextMenu(event);
  2582. contextMenu.appendApplicableItems(this._resource);
  2583. if (this._resource.request)
  2584. contextMenu.appendApplicableItems(this._resource.request);
  2585. contextMenu.show();
  2586. },
  2587.  
  2588. _setBubbleText: function(x)
  2589. {
  2590. if (!this._bubbleElement) {
  2591. this._bubbleElement = document.createElement("div");
  2592. this._bubbleElement.className = "bubble";
  2593. this._statusElement.appendChild(this._bubbleElement);
  2594. }
  2595.  
  2596. this._bubbleElement.textContent = x;
  2597. },
  2598.  
  2599. _resetBubble: function()
  2600. {
  2601. if (this._bubbleElement) {
  2602. this._bubbleElement.textContent = "";
  2603. this._bubbleElement.removeStyleClass("search-matches");
  2604. this._bubbleElement.removeStyleClass("warning");
  2605. this._bubbleElement.removeStyleClass("error");
  2606. }
  2607. },
  2608.  
  2609. _resetSearchResults: function()
  2610. {
  2611. this._resetBubble();
  2612. this._searchMatchesCount = 0;
  2613. },
  2614.  
  2615. get searchMatchesCount()
  2616. {
  2617. return this._searchMatchesCount;
  2618. },
  2619.  
  2620. searchMatchesFound: function(matchesCount)
  2621. {
  2622. this._resetSearchResults();
  2623.  
  2624. this._searchMatchesCount = matchesCount;
  2625. this._setBubbleText(matchesCount);
  2626. this._bubbleElement.addStyleClass("search-matches");
  2627.  
  2628.  
  2629. var currentAncestor = this.parent;
  2630. while (currentAncestor && !currentAncestor.root) {
  2631. if (!currentAncestor.expanded)
  2632. currentAncestor.expand();
  2633. currentAncestor = currentAncestor.parent;
  2634. }
  2635. },
  2636.  
  2637. _updateErrorsAndWarningsBubbles: function()
  2638. {
  2639. if (this._storagePanel.currentQuery)
  2640. return;
  2641.  
  2642. this._resetBubble();
  2643.  
  2644. if (this._resource.warnings || this._resource.errors)
  2645. this._setBubbleText(this._resource.warnings + this._resource.errors);
  2646.  
  2647. if (this._resource.warnings)
  2648. this._bubbleElement.addStyleClass("warning");
  2649.  
  2650. if (this._resource.errors)
  2651. this._bubbleElement.addStyleClass("error");
  2652. },
  2653.  
  2654. _consoleMessagesCleared: function()
  2655. {
  2656.  
  2657. if (this._sourceView)
  2658. this._sourceView.clearMessages();
  2659.  
  2660. this._updateErrorsAndWarningsBubbles();
  2661. },
  2662.  
  2663. _consoleMessageAdded: function(event)
  2664. {
  2665. var msg = event.data;
  2666. if (this._sourceView)
  2667. this._sourceView.addMessage(msg);
  2668. this._updateErrorsAndWarningsBubbles();
  2669. },
  2670.  
  2671. sourceView: function()
  2672. {
  2673. if (!this._sourceView) {
  2674. this._sourceView = new WebInspector.ResourceSourceFrame(this._resource);
  2675. if (this._resource.messages) {
  2676. for (var i = 0; i < this._resource.messages.length; i++)
  2677. this._sourceView.addMessage(this._resource.messages[i]);
  2678. }
  2679. }
  2680. return this._sourceView;
  2681. },
  2682.  
  2683. __proto__: WebInspector.BaseStorageTreeElement.prototype
  2684. }
  2685.  
  2686.  
  2687. WebInspector.DatabaseTreeElement = function(storagePanel, database)
  2688. {
  2689. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, database.name, ["database-storage-tree-item"], true);
  2690. this._database = database;
  2691. }
  2692.  
  2693. WebInspector.DatabaseTreeElement.prototype = {
  2694. get itemURL()
  2695. {
  2696. return "database://" + encodeURI(this._database.name);
  2697. },
  2698.  
  2699. onselect: function()
  2700. {
  2701. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  2702. this._storagePanel._showDatabase(this._database);
  2703. },
  2704.  
  2705. onexpand: function()
  2706. {
  2707. this._updateChildren();
  2708. },
  2709.  
  2710. _updateChildren: function()
  2711. {
  2712. this.removeChildren();
  2713.  
  2714. function tableNamesCallback(tableNames)
  2715. {
  2716. var tableNamesLength = tableNames.length;
  2717. for (var i = 0; i < tableNamesLength; ++i)
  2718. this.appendChild(new WebInspector.DatabaseTableTreeElement(this._storagePanel, this._database, tableNames[i]));
  2719. }
  2720. this._database.getTableNames(tableNamesCallback.bind(this));
  2721. },
  2722.  
  2723. __proto__: WebInspector.BaseStorageTreeElement.prototype
  2724. }
  2725.  
  2726.  
  2727. WebInspector.DatabaseTableTreeElement = function(storagePanel, database, tableName)
  2728. {
  2729. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, tableName, ["database-storage-tree-item"]);
  2730. this._database = database;
  2731. this._tableName = tableName;
  2732. }
  2733.  
  2734. WebInspector.DatabaseTableTreeElement.prototype = {
  2735. get itemURL()
  2736. {
  2737. return "database://" + encodeURI(this._database.name) + "/" + encodeURI(this._tableName);
  2738. },
  2739.  
  2740. onselect: function()
  2741. {
  2742. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  2743. this._storagePanel._showDatabase(this._database, this._tableName);
  2744. },
  2745.  
  2746. __proto__: WebInspector.BaseStorageTreeElement.prototype
  2747. }
  2748.  
  2749.  
  2750. WebInspector.IndexedDBTreeElement = function(storagePanel)
  2751. {
  2752. WebInspector.StorageCategoryTreeElement.call(this, storagePanel, WebInspector.UIString("IndexedDB"), "IndexedDB", ["indexed-db-storage-tree-item"]);
  2753. }
  2754.  
  2755. WebInspector.IndexedDBTreeElement.prototype = {
  2756. onexpand: function()
  2757. {
  2758. WebInspector.StorageCategoryTreeElement.prototype.onexpand.call(this);
  2759. if (!this._indexedDBModel)
  2760. this._createIndexedDBModel();
  2761. },
  2762.  
  2763. onattach: function()
  2764. {
  2765. WebInspector.StorageCategoryTreeElement.prototype.onattach.call(this);
  2766. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  2767. },
  2768.  
  2769. _handleContextMenuEvent: function(event)
  2770. {
  2771. var contextMenu = new WebInspector.ContextMenu(event);
  2772. contextMenu.appendItem(WebInspector.UIString("Refresh IndexedDB"), this.refreshIndexedDB.bind(this));
  2773. contextMenu.show();
  2774. },
  2775.  
  2776. _createIndexedDBModel: function()
  2777. {
  2778. this._indexedDBModel = new WebInspector.IndexedDBModel();
  2779. this._idbDatabaseTreeElements = [];
  2780. this._indexedDBModel.addEventListener(WebInspector.IndexedDBModel.EventTypes.DatabaseAdded, this._indexedDBAdded, this);
  2781. this._indexedDBModel.addEventListener(WebInspector.IndexedDBModel.EventTypes.DatabaseRemoved, this._indexedDBRemoved, this);
  2782. this._indexedDBModel.addEventListener(WebInspector.IndexedDBModel.EventTypes.DatabaseLoaded, this._indexedDBLoaded, this);
  2783. },
  2784.  
  2785. refreshIndexedDB: function()
  2786. {
  2787. if (!this._indexedDBModel) {
  2788. this._createIndexedDBModel();
  2789. return;
  2790. }
  2791.  
  2792. this._indexedDBModel.refreshDatabaseNames();
  2793. },
  2794.  
  2795.  
  2796. _indexedDBAdded: function(event)
  2797. {
  2798. var databaseId =   (event.data);
  2799.  
  2800. var idbDatabaseTreeElement = new WebInspector.IDBDatabaseTreeElement(this._storagePanel, this._indexedDBModel, databaseId);
  2801. this._idbDatabaseTreeElements.push(idbDatabaseTreeElement);
  2802. this.appendChild(idbDatabaseTreeElement);
  2803.  
  2804. this._indexedDBModel.refreshDatabase(databaseId);
  2805. },
  2806.  
  2807.  
  2808. _indexedDBRemoved: function(event)
  2809. {
  2810. var databaseId =   (event.data);
  2811.  
  2812. var idbDatabaseTreeElement = this._idbDatabaseTreeElement(databaseId)
  2813. if (!idbDatabaseTreeElement)
  2814. return;
  2815.  
  2816. idbDatabaseTreeElement.clear();
  2817. this.removeChild(idbDatabaseTreeElement);
  2818. this._idbDatabaseTreeElements.remove(idbDatabaseTreeElement);
  2819. },
  2820.  
  2821.  
  2822. _indexedDBLoaded: function(event)
  2823. {
  2824. var database =   (event.data);
  2825.  
  2826. var idbDatabaseTreeElement = this._idbDatabaseTreeElement(database.databaseId)
  2827. if (!idbDatabaseTreeElement)
  2828. return;
  2829.  
  2830. idbDatabaseTreeElement.update(database);
  2831. },
  2832.  
  2833.  
  2834. _idbDatabaseTreeElement: function(databaseId)
  2835. {
  2836. var index = -1;
  2837. for (var i = 0; i < this._idbDatabaseTreeElements.length; ++i) {
  2838. if (this._idbDatabaseTreeElements[i]._databaseId.equals(databaseId)) {
  2839. index = i;
  2840. break;
  2841. }
  2842. }
  2843. if (index !== -1)
  2844. return this._idbDatabaseTreeElements[i];
  2845. return null;
  2846. },
  2847.  
  2848. __proto__: WebInspector.StorageCategoryTreeElement.prototype
  2849. }
  2850.  
  2851.  
  2852. WebInspector.FileSystemListTreeElement = function(storagePanel)
  2853. {
  2854. WebInspector.StorageCategoryTreeElement.call(this, storagePanel, WebInspector.UIString("FileSystem"), "FileSystem", ["file-system-storage-tree-item"]);
  2855. }
  2856.  
  2857. WebInspector.FileSystemListTreeElement.prototype = {
  2858. onexpand: function()
  2859. {
  2860. WebInspector.StorageCategoryTreeElement.prototype.onexpand.call(this);
  2861. this._refreshFileSystem();
  2862. },
  2863.  
  2864. onattach: function()
  2865. {
  2866. WebInspector.StorageCategoryTreeElement.prototype.onattach.call(this);
  2867. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  2868. },
  2869.  
  2870. _handleContextMenuEvent: function(event)
  2871. {
  2872. var contextMenu = new WebInspector.ContextMenu(event);
  2873. contextMenu.appendItem(WebInspector.UIString("Refresh FileSystem List"), this._refreshFileSystem.bind(this));
  2874. contextMenu.show();
  2875. },
  2876.  
  2877. _fileSystemAdded: function(event)
  2878. {
  2879. var fileSystem =   (event.data);
  2880. var fileSystemTreeElement = new WebInspector.FileSystemTreeElement(this._storagePanel, fileSystem);
  2881. this.appendChild(fileSystemTreeElement);
  2882. },
  2883.  
  2884. _fileSystemRemoved: function(event)
  2885. {
  2886. var fileSystem =   (event.data);
  2887. var fileSystemTreeElement = this._fileSystemTreeElementByName(fileSystem.name);
  2888. if (!fileSystemTreeElement)
  2889. return;
  2890. fileSystemTreeElement.clear();
  2891. this.removeChild(fileSystemTreeElement);
  2892. },
  2893.  
  2894. _fileSystemTreeElementByName: function(fileSystemName)
  2895. {
  2896. for (var i = 0; i < this.children.length; ++i) {
  2897. var child =   (this.children[i]);
  2898. if (child.fileSystemName === fileSystemName)
  2899. return this.children[i];
  2900. }
  2901. return null;
  2902. },
  2903.  
  2904. _refreshFileSystem: function()
  2905. {
  2906. if (!this._fileSystemModel) {
  2907. this._fileSystemModel = new WebInspector.FileSystemModel();
  2908. this._fileSystemModel.addEventListener(WebInspector.FileSystemModel.EventTypes.FileSystemAdded, this._fileSystemAdded, this);
  2909. this._fileSystemModel.addEventListener(WebInspector.FileSystemModel.EventTypes.FileSystemRemoved, this._fileSystemRemoved, this);
  2910. }
  2911.  
  2912. this._fileSystemModel.refreshFileSystemList();
  2913. },
  2914.  
  2915. __proto__: WebInspector.StorageCategoryTreeElement.prototype
  2916. }
  2917.  
  2918.  
  2919. WebInspector.IDBDatabaseTreeElement = function(storagePanel, model, databaseId)
  2920. {
  2921. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, databaseId.name + " - " + databaseId.securityOrigin, ["indexed-db-storage-tree-item"]);
  2922. this._model = model;
  2923. this._databaseId = databaseId;
  2924. this._idbObjectStoreTreeElements = {};
  2925. }
  2926.  
  2927. WebInspector.IDBDatabaseTreeElement.prototype = {
  2928. get itemURL()
  2929. {
  2930. return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._databaseId.name;
  2931. },
  2932.  
  2933. onattach: function()
  2934. {
  2935. WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
  2936. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
  2937. },
  2938.  
  2939. _handleContextMenuEvent: function(event)
  2940. {
  2941. var contextMenu = new WebInspector.ContextMenu(event);
  2942. contextMenu.appendItem(WebInspector.UIString("Refresh IndexedDB"), this._refreshIndexedDB.bind(this));
  2943. contextMenu.show();
  2944. },
  2945.  
  2946. _refreshIndexedDB: function(event)
  2947. {
  2948. this._model.refreshDatabaseNames();
  2949. },
  2950.  
  2951.  
  2952. update: function(database)
  2953. {
  2954. this._database = database;
  2955. var objectStoreNames = {};
  2956. for (var objectStoreName in this._database.objectStores) {
  2957. var objectStore = this._database.objectStores[objectStoreName];
  2958. objectStoreNames[objectStore.name] = true;
  2959. if (!this._idbObjectStoreTreeElements[objectStore.name]) {
  2960. var idbObjectStoreTreeElement = new WebInspector.IDBObjectStoreTreeElement(this._storagePanel, this._model, this._databaseId, objectStore);
  2961. this._idbObjectStoreTreeElements[objectStore.name] = idbObjectStoreTreeElement;
  2962. this.appendChild(idbObjectStoreTreeElement);
  2963. }
  2964. this._idbObjectStoreTreeElements[objectStore.name].update(objectStore);
  2965. }
  2966. for (var objectStoreName in this._idbObjectStoreTreeElements) {
  2967. if (!objectStoreNames[objectStoreName])
  2968. this._objectStoreRemoved(objectStoreName);
  2969. }
  2970.  
  2971. if (this.children.length) {
  2972. this.hasChildren = true;
  2973. this.expand();
  2974. }
  2975.  
  2976. if (this._view)
  2977. this._view.update(database);
  2978.  
  2979. this._updateTooltip();
  2980. },
  2981.  
  2982. _updateTooltip: function()
  2983. {
  2984. this.tooltip = WebInspector.UIString("Version") + ": " + this._database.version;
  2985. },
  2986.  
  2987. onselect: function()
  2988. {
  2989. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  2990. if (!this._view)
  2991. this._view = new WebInspector.IDBDatabaseView(this._database);
  2992.  
  2993. this._storagePanel.showIndexedDB(this._view);
  2994. },
  2995.  
  2996.  
  2997. _objectStoreRemoved: function(objectStoreName)
  2998. {
  2999. var objectStoreTreeElement = this._idbObjectStoreTreeElements[objectStoreName];
  3000. objectStoreTreeElement.clear();
  3001. this.removeChild(objectStoreTreeElement);
  3002. delete this._idbObjectStoreTreeElements[objectStoreName];
  3003. },
  3004.  
  3005. clear: function()
  3006. {
  3007. for (var objectStoreName in this._idbObjectStoreTreeElements)
  3008. this._objectStoreRemoved(objectStoreName);
  3009. },
  3010.  
  3011. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3012. }
  3013.  
  3014.  
  3015. WebInspector.IDBObjectStoreTreeElement = function(storagePanel, model, databaseId, objectStore)
  3016. {
  3017. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, objectStore.name, ["indexed-db-object-store-storage-tree-item"]);
  3018. this._model = model;
  3019. this._databaseId = databaseId;
  3020. this._idbIndexTreeElements = {};
  3021. }
  3022.  
  3023. WebInspector.IDBObjectStoreTreeElement.prototype = {
  3024. get itemURL()
  3025. {
  3026. return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._databaseId.name + "/" + this._objectStore.name;
  3027. },
  3028.  
  3029.  
  3030. update: function(objectStore)
  3031. {
  3032. this._objectStore = objectStore;
  3033.  
  3034. var indexNames = {};
  3035. for (var indexName in this._objectStore.indexes) {
  3036. var index = this._objectStore.indexes[indexName];
  3037. indexNames[index.name] = true;
  3038. if (!this._idbIndexTreeElements[index.name]) {
  3039. var idbIndexTreeElement = new WebInspector.IDBIndexTreeElement(this._storagePanel, this._model, this._databaseId, this._objectStore, index);
  3040. this._idbIndexTreeElements[index.name] = idbIndexTreeElement;
  3041. this.appendChild(idbIndexTreeElement);
  3042. }
  3043. this._idbIndexTreeElements[index.name].update(index);
  3044. }
  3045. for (var indexName in this._idbIndexTreeElements) {
  3046. if (!indexNames[indexName])
  3047. this._indexRemoved(indexName);
  3048. }
  3049. for (var indexName in this._idbIndexTreeElements) {
  3050. if (!indexNames[indexName]) {
  3051. this.removeChild(this._idbIndexTreeElements[indexName]);
  3052. delete this._idbIndexTreeElements[indexName];
  3053. }
  3054. }
  3055.  
  3056. if (this.children.length) {
  3057. this.hasChildren = true;
  3058. this.expand();
  3059. }
  3060.  
  3061. if (this._view)
  3062. this._view.update(this._objectStore);
  3063.  
  3064. this._updateTooltip();
  3065. },
  3066.  
  3067. _updateTooltip: function()
  3068. {
  3069.  
  3070. var keyPathString = this._objectStore.keyPathString;
  3071. var tooltipString = keyPathString !== null ? (WebInspector.UIString("Key path: ") + keyPathString) : "";
  3072. if (this._objectStore.autoIncrement)
  3073. tooltipString += "\n" + WebInspector.UIString("autoIncrement");
  3074. this.tooltip = tooltipString
  3075. },
  3076.  
  3077. onselect: function()
  3078. {
  3079. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3080. if (!this._view)
  3081. this._view = new WebInspector.IDBDataView(this._model, this._databaseId, this._objectStore, null);
  3082.  
  3083. this._storagePanel.showIndexedDB(this._view);
  3084. },
  3085.  
  3086.  
  3087. _indexRemoved: function(indexName)
  3088. {
  3089. var indexTreeElement = this._idbIndexTreeElements[indexName];
  3090. indexTreeElement.clear();
  3091. this.removeChild(indexTreeElement);
  3092. delete this._idbIndexTreeElements[indexName];
  3093. },
  3094.  
  3095. clear: function()
  3096. {
  3097. for (var indexName in this._idbIndexTreeElements)
  3098. this._indexRemoved(indexName);
  3099. if (this._view)
  3100. this._view.clear();
  3101. },
  3102.  
  3103. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3104. }
  3105.  
  3106.  
  3107. WebInspector.IDBIndexTreeElement = function(storagePanel, model, databaseId, objectStore, index)
  3108. {
  3109. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, index.name, ["indexed-db-index-storage-tree-item"]);
  3110. this._model = model;
  3111. this._databaseId = databaseId;
  3112. this._objectStore = objectStore;
  3113. this._index = index;
  3114. }
  3115.  
  3116. WebInspector.IDBIndexTreeElement.prototype = {
  3117. get itemURL()
  3118. {
  3119. return "indexedDB://" + this._databaseId.securityOrigin + "/" + this._databaseId.name + "/" + this._objectStore.name + "/" + this._index.name;
  3120. },
  3121.  
  3122.  
  3123. update: function(index)
  3124. {
  3125. this._index = index;
  3126.  
  3127. if (this._view)
  3128. this._view.update(this._index);
  3129.  
  3130. this._updateTooltip();
  3131. },
  3132.  
  3133. _updateTooltip: function()
  3134. {
  3135. var tooltipLines = [];
  3136. var keyPathString = this._index.keyPathString;
  3137. tooltipLines.push(WebInspector.UIString("Key path: ") + keyPathString);
  3138. if (this._index.unique)
  3139. tooltipLines.push(WebInspector.UIString("unique"));
  3140. if (this._index.multiEntry)
  3141. tooltipLines.push(WebInspector.UIString("multiEntry"));
  3142. this.tooltip = tooltipLines.join("\n");
  3143. },
  3144.  
  3145. onselect: function()
  3146. {
  3147. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3148. if (!this._view)
  3149. this._view = new WebInspector.IDBDataView(this._model, this._databaseId, this._objectStore, this._index);
  3150.  
  3151. this._storagePanel.showIndexedDB(this._view);
  3152. },
  3153.  
  3154. clear: function()
  3155. {
  3156. if (this._view)
  3157. this._view.clear();
  3158. },
  3159.  
  3160. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3161. }
  3162.  
  3163.  
  3164. WebInspector.DOMStorageTreeElement = function(storagePanel, domStorage, className)
  3165. {
  3166. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, domStorage.domain ? domStorage.domain : WebInspector.UIString("Local Files"), ["domstorage-storage-tree-item", className]);
  3167. this._domStorage = domStorage;
  3168. }
  3169.  
  3170. WebInspector.DOMStorageTreeElement.prototype = {
  3171. get itemURL()
  3172. {
  3173. return "storage://" + this._domStorage.domain + "/" + (this._domStorage.isLocalStorage ? "local" : "session");
  3174. },
  3175.  
  3176. onselect: function()
  3177. {
  3178. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3179. this._storagePanel._showDOMStorage(this._domStorage);
  3180. },
  3181.  
  3182. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3183. }
  3184.  
  3185.  
  3186. WebInspector.CookieTreeElement = function(storagePanel, cookieDomain)
  3187. {
  3188. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, cookieDomain ? cookieDomain : WebInspector.UIString("Local Files"), ["cookie-storage-tree-item"]);
  3189. this._cookieDomain = cookieDomain;
  3190. }
  3191.  
  3192. WebInspector.CookieTreeElement.prototype = {
  3193. get itemURL()
  3194. {
  3195. return "cookies://" + this._cookieDomain;
  3196. },
  3197.  
  3198. onselect: function()
  3199. {
  3200. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3201. this._storagePanel.showCookies(this, this._cookieDomain);
  3202. },
  3203.  
  3204. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3205. }
  3206.  
  3207.  
  3208. WebInspector.ApplicationCacheManifestTreeElement = function(storagePanel, manifestURL)
  3209. {
  3210. var title = new WebInspector.ParsedURL(manifestURL).displayName;
  3211. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, title, ["application-cache-storage-tree-item"]);
  3212. this.tooltip = manifestURL;
  3213. this._manifestURL = manifestURL;
  3214. }
  3215.  
  3216. WebInspector.ApplicationCacheManifestTreeElement.prototype = {
  3217. get itemURL()
  3218. {
  3219. return "appcache://" + this._manifestURL;
  3220. },
  3221.  
  3222. get manifestURL()
  3223. {
  3224. return this._manifestURL;
  3225. },
  3226.  
  3227. onselect: function()
  3228. {
  3229. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3230. this._storagePanel.showCategoryView(this._manifestURL);
  3231. },
  3232.  
  3233. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3234. }
  3235.  
  3236.  
  3237. WebInspector.ApplicationCacheFrameTreeElement = function(storagePanel, frameId, manifestURL)
  3238. {
  3239. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, "", ["frame-storage-tree-item"]);
  3240. this._frameId = frameId;
  3241. this._manifestURL = manifestURL;
  3242. this._refreshTitles();
  3243. }
  3244.  
  3245. WebInspector.ApplicationCacheFrameTreeElement.prototype = {
  3246. get itemURL()
  3247. {
  3248. return "appcache://" + this._manifestURL + "/" + encodeURI(this.displayName);
  3249. },
  3250.  
  3251. get frameId()
  3252. {
  3253. return this._frameId;
  3254. },
  3255.  
  3256. get manifestURL()
  3257. {
  3258. return this._manifestURL;
  3259. },
  3260.  
  3261. _refreshTitles: function()
  3262. {
  3263. var frame = WebInspector.resourceTreeModel.frameForId(this._frameId);
  3264. if (!frame) {
  3265. this.subtitleText = WebInspector.UIString("new frame");
  3266. return;
  3267. }
  3268. this.titleText = frame.name;
  3269. this.subtitleText = new WebInspector.ParsedURL(frame.url).displayName;
  3270. },
  3271.  
  3272. frameNavigated: function()
  3273. {
  3274. this._refreshTitles();
  3275. },
  3276.  
  3277. onselect: function()
  3278. {
  3279. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3280. this._storagePanel.showApplicationCache(this._frameId);
  3281. },
  3282.  
  3283. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3284. }
  3285.  
  3286.  
  3287. WebInspector.FileSystemTreeElement = function(storagePanel, fileSystem)
  3288. {
  3289. var displayName = fileSystem.type + " - " + fileSystem.origin;
  3290. WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, displayName, ["file-system-storage-tree-item"]);
  3291. this._fileSystem = fileSystem;
  3292. }
  3293.  
  3294. WebInspector.FileSystemTreeElement.prototype = {
  3295. get fileSystemName()
  3296. {
  3297. return this._fileSystem.name;
  3298. },
  3299.  
  3300. get itemURL()
  3301. {
  3302. return "filesystem://" + this._fileSystem.name;
  3303. },
  3304.  
  3305. onselect: function()
  3306. {
  3307. WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
  3308. this._fileSystemView = new WebInspector.FileSystemView(this._fileSystem);
  3309. this._storagePanel.showFileSystem(this._fileSystemView);
  3310. },
  3311.  
  3312. clear: function()
  3313. {
  3314. if (this.fileSystemView && this._storagePanel.visibleView == this.fileSystemView)
  3315. this._storagePanel.closeVisibleView();
  3316. },
  3317.  
  3318. __proto__: WebInspector.BaseStorageTreeElement.prototype
  3319. }
  3320.  
  3321.  
  3322. WebInspector.StorageCategoryView = function()
  3323. {
  3324. WebInspector.View.call(this);
  3325.  
  3326. this.element.addStyleClass("storage-view");
  3327. this._emptyView = new WebInspector.EmptyView("");
  3328. this._emptyView.show(this.element);
  3329. }
  3330.  
  3331. WebInspector.StorageCategoryView.prototype = {
  3332. setText: function(text)
  3333. {
  3334. this._emptyView.text = text;
  3335. },
  3336.  
  3337. __proto__: WebInspector.View.prototype
  3338. }
  3339.  
  3340.  
  3341. WebInspector.ResourcesSearchController = function(rootElement, matchesCount)
  3342. {
  3343. this._root = rootElement;
  3344. this._matchesCount = matchesCount;
  3345. this._traverser = new WebInspector.SearchResultsTreeElementsTraverser(rootElement);
  3346. this._lastTreeElement = null;
  3347. this._lastIndex = -1;
  3348. }
  3349.  
  3350. WebInspector.ResourcesSearchController.prototype = {
  3351.  
  3352. nextSearchResult: function(currentTreeElement)
  3353. {
  3354. if (!currentTreeElement)
  3355. return this._searchResult(this._traverser.first(), 0, 1);
  3356.  
  3357. if (!currentTreeElement.searchMatchesCount)
  3358. return this._searchResult(this._traverser.next(currentTreeElement), 0);
  3359.  
  3360. if (this._lastTreeElement !== currentTreeElement || this._lastIndex === -1)
  3361. return this._searchResult(currentTreeElement, 0);
  3362.  
  3363. if (this._lastIndex == currentTreeElement.searchMatchesCount - 1)
  3364. return this._searchResult(this._traverser.next(currentTreeElement), 0, this._currentMatchIndex % this._matchesCount + 1);
  3365.  
  3366. return this._searchResult(currentTreeElement, this._lastIndex + 1, this._currentMatchIndex + 1);
  3367. },
  3368.  
  3369.  
  3370. previousSearchResult: function(currentTreeElement)
  3371. {
  3372. if (!currentTreeElement) {
  3373. var treeElement = this._traverser.last();
  3374. return this._searchResult(treeElement, treeElement.searchMatchesCount - 1, this._matchesCount);
  3375. }
  3376.  
  3377. if (currentTreeElement.searchMatchesCount && this._lastTreeElement === currentTreeElement) {
  3378. if (this._lastIndex > 0)
  3379. return this._searchResult(currentTreeElement, this._lastIndex - 1, this._currentMatchIndex - 1);
  3380. else {
  3381. var treeElement = this._traverser.previous(currentTreeElement);
  3382. var currentMatchIndex = this._currentMatchIndex - 1 ? this._currentMatchIndex - 1 : this._matchesCount;
  3383. return this._searchResult(treeElement, treeElement.searchMatchesCount - 1, currentMatchIndex);
  3384. }
  3385. }
  3386.  
  3387. var treeElement = this._traverser.previous(currentTreeElement)
  3388. return this._searchResult(treeElement, treeElement.searchMatchesCount - 1);
  3389. },
  3390.  
  3391.  
  3392. _searchResult: function(treeElement, index, currentMatchIndex)
  3393. {
  3394. this._lastTreeElement = treeElement;
  3395. this._lastIndex = index;
  3396. if (!currentMatchIndex)
  3397. currentMatchIndex = this._traverser.matchIndex(treeElement, index);
  3398. this._currentMatchIndex = currentMatchIndex;
  3399. return {treeElement: treeElement, index: index, currentMatchIndex: currentMatchIndex};
  3400. }
  3401. }
  3402.  
  3403.  
  3404. WebInspector.SearchResultsTreeElementsTraverser = function(rootElement)
  3405. {
  3406. this._root = rootElement;
  3407. }
  3408.  
  3409. WebInspector.SearchResultsTreeElementsTraverser.prototype = {
  3410.  
  3411. first: function()
  3412. {
  3413. return this.next(this._root);
  3414. },
  3415.  
  3416.  
  3417. last: function()
  3418. {
  3419. return this.previous(this._root);
  3420. },
  3421.  
  3422.  
  3423. next: function(startTreeElement)
  3424. {
  3425. var treeElement = startTreeElement;
  3426. do {
  3427. treeElement = this._traverseNext(treeElement) || this._root;
  3428. } while (treeElement != startTreeElement && !this._elementSearchMatchesCount(treeElement));
  3429. return treeElement;
  3430. },
  3431.  
  3432.  
  3433. previous: function(startTreeElement)
  3434. {
  3435. var treeElement = startTreeElement;
  3436. do {
  3437. treeElement = this._traversePrevious(treeElement) || this._lastTreeElement();
  3438. } while (treeElement != startTreeElement && !this._elementSearchMatchesCount(treeElement));
  3439. return treeElement;
  3440. },
  3441.  
  3442.  
  3443. matchIndex: function(startTreeElement, index)
  3444. {
  3445. var matchIndex = 1;
  3446. var treeElement = this._root;
  3447. while (treeElement != startTreeElement) {
  3448. matchIndex += this._elementSearchMatchesCount(treeElement);
  3449. treeElement = this._traverseNext(treeElement) || this._root;
  3450. if (treeElement === this._root)
  3451. return 0;
  3452. }
  3453. return matchIndex + index;
  3454. },
  3455.  
  3456.  
  3457. _elementSearchMatchesCount: function(treeElement)
  3458. {
  3459. return treeElement.searchMatchesCount;
  3460. },
  3461.  
  3462.  
  3463. _traverseNext: function(treeElement)
  3464. {
  3465. return   (treeElement.traverseNextTreeElement(false, this._root, true));
  3466. },
  3467.  
  3468.  
  3469. _traversePrevious: function(treeElement)
  3470. {
  3471. return   (treeElement.traversePreviousTreeElement(false, true));
  3472. },
  3473.  
  3474.  
  3475. _lastTreeElement: function()
  3476. {
  3477. var treeElement = this._root;
  3478. var nextTreeElement;
  3479. while (nextTreeElement = this._traverseNext(treeElement))
  3480. treeElement = nextTreeElement;
  3481. return treeElement;
  3482. }
  3483. }
  3484.